Ssh
舊 Linux 拒絕來自新安裝的 Windows 的 ssh id_rsa 密鑰
我長期維護舊的 Linux 伺服器(CentOS 6.5)。我使用 ‘pub key auth’ 通過 ssh 訪問該 Linux 伺服器。
現在我剛買了一台新的 Windows(win10 或 11 不確定)筆記型電腦並安裝了“Git for win 2.33”,當我像往常一樣嘗試從新筆記型電腦上 ssh 時,我得到了:
$ ssh -i ~/.ssh/id_rsa.bridge_to_home -p 5122 -vv shaozr@{ip addr} OpenSSH_8.8p1, OpenSSL 1.1.1m 14 Dec 2021 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolve_canonicalize: hostname 27.115.62.170 is address debug1: Connecting to 27.115.62.170 [27.115.62.170] port 5122. debug1: Connection established. debug1: identity file /c/Users/43141/.ssh/id_rsa.bridge_to_home type -1 debug1: identity file /c/Users/43141/.ssh/id_rsa.bridge_to_home-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.8 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: compat_banner: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000002 debug2: fd 4 setting O_NONBLOCK debug1: Authenticating to 27.115.62.170:5122 as 'shaozr' debug1: load_hostkeys: fopen /c/Users/43141/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /c/Users/43141/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug2: local client KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c debug2: host key algorithms: ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256 debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none,zlib@openssh.com,zlib debug2: compression stoc: none,zlib@openssh.com,zlib debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug2: peer server KEXINIT proposal debug2: KEX algorithms: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: host key algorithms: ssh-rsa,ssh-dss debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: MACs ctos: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: MACs stoc: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: compression ctos: none,zlib@openssh.com debug2: compression stoc: none,zlib@openssh.com debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug1: kex: algorithm: diffie-hellman-group-exchange-sha256 debug1: kex: host key algorithm: (no match) Unable to negotiate with 27.115.62.170 port 5122: no matching host key type found. Their offer: ssh-rsa,ssh-dss
這很奇怪。
我仍然可以從我的舊 PC 上 ssh 到那個 linux,我可以從我的新筆記型電腦上通過 ssh(到著名的 git repo 提供商)進行 git clone。
似乎雙方都’ssh OK’,但為什麼CentOS6.6拒絕’Git for win 2.33’的id_ras密鑰?
剛剛在安裝了 OpenSSH 9 的新 Cygwin 的新 Windows 機器上執行時遇到了這個問題。事實證明,在 8.something 中,OpenSSH 團隊預設禁用了舊的 ssh-rsa 加密算法。(見https://www.openssh.com/releasenotes.html)
不是伺服器拒絕你;那是你的新客戶端不願意說 ssh-rsa,這是所有舊的 OpenSSH 守護程序都可以說的。
您可以指示您的客戶重新啟用它們,但這是一種解決方法。您將需要升級伺服器上的 ssh 守護程序。
因此,解決方法是在您的客戶端上創建一個 ssh 配置文件,在 $HOME/.ssh/config 中,並在其中放置如下內容:
Host HOSTNAME HostKeyAlgorithms +ssh-rsa PubkeyAcceptedAlgorithms +ssh-rsa
將 HOSTNAME 替換為與您要連接的主機名匹配的正則表達式。