使用IPv6位址的SSH連線
我正嘗試使用 IPv6 連接到 Hetzner Cloud 上的一部機器。ssh 2a01:4f8:c17:2000::/64
無效,但 ssh root@2a01:4f8:c17:2000::1
則有效。
IPv6 地址是從 Hetzner Cloud 控制台複製的。
可以設定 ~/.ssh/config
檔案,為 IPv4 和 IPv6 地址應用不同的 proxy 規則。此設定允許您為 IPv4 地址指定 proxy 命令,同時以不同的方式處理 IPv6 地址。
Host 192.168.1.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Host *.*.*.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand corkscrew localhost 7890 %h %p
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
執行 ssh root@192.168.1.3
時,以下輸出顯示 SSH 客戶端正在應用 ~/.ssh/config
檔案中的設定選項:
debug1: Reading configuration data /Users/lzwjava/.ssh/config
debug1: /Users/lzwjava/.ssh/config line 1: Applying options for 192.168.1.*
debug1: /Users/lzwjava/.ssh/config line 5: Applying options for *.*.*.*
debug2: add_identity_file: ignoring duplicate key ~/.ssh/id_rsa
debug1: /Users/lzwjava/.ssh/config line 10: Applying options for *
debug2: add_identity_file: ignoring duplicate key ~/.ssh/id_rsa
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.1.3 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/lzwjava/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/lzwjava/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: channel_clear_timeouts: clearing
debug1: Executing proxy command: exec corkscrew localhost 7890 192.168.1.3 22
SSH 連線速度明顯緩慢,所以我回復到以下更簡單的設定:
Host 192.168.1.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand corkscrew localhost 7890 %h %p
問題出現在使用 IPv6 地址和 ProxyCommand corkscrew localhost 7890 %h %p
指令時,因為此 proxy 命令可能無法正確處理 IPv6 地址。