Ssh

gcloud SSH 連接要求輸入密碼而不是密碼

  • October 28, 2020

我在 Google Cloud Platform 上設置了兩個虛擬機。server1使用 Ubuntu 16.04 映像

$$ g1-small (1 vCPU, 1.7 GB memory) $$; 新創建的 VM 名為server2,使用 CoreOS Stable 映像$$ f1-micro (1 vCPU, 0.6 GB memory) $$. server2主要問題是即使我使用相同的 SSH 密鑰和使用者也無法連接。

我將使用此連結比較來自ssh -v.


為了確保我測試了這個權利,我刪除了文件夾中的文件google_compute_engine、和內容。google_compute_engine.pub``google_compute_known_hosts``known_hosts``/Users/userz/.ssh

然後執行命令gcloud init然後gcloud compute config-ssh,它檢測到沒有 SSH 密鑰並指導我創建一個新密鑰,同時要求輸入密碼,而不是密碼。新的 SSH 密鑰就是本次測試中使用的密鑰。

如果您看到 的第一個連結server1,則 ssh 最終會要求輸入密碼。但是對於server2ssh 最終要求輸入密碼,我輸入什麼並不重要,它只是每次都輸入錯誤。

我嘗試的密碼是:相同的密碼、我的 google 帳戶登錄密碼、本地電腦的管理員密碼,以及我記得使用的所有其他密碼。然而輸入錯誤。

當我使用相同的方法連接到虛擬機時,為什麼會出現這種差異?我可以做些什麼來解決這個問題,因為我不知道也沒有設置任何密碼server2(新創建的)?

我可以補充一點,連接通過Cloud Shell要求輸入密碼並輕鬆連接。


server1輸出:

ssh -v server1
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/userz/.ssh/config
debug1: /Users/userz/.ssh/config line 51: Applying options for server1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to XXX.XXX.XX.XX [XXX.XXX.XX.XX] port 22.
debug1: Connection established.
debug1: identity file /Users/userz/.ssh/google_compute_engine type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/userz/.ssh/google_compute_engine-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to XXX.XXX.XX.XX:22 as 'userz'
debug1: using hostkeyalias: compute.hostkeyaliasX
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
debug1: using hostkeyalias: compute.hostkeyaliasX
debug1: Host 'compute.hostkeyaliasX' is known and matches the ECDSA host key.
debug1: Found key in /Users/userz/.ssh/google_compute_known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/userz/.ssh/google_compute_engine
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
Enter passphrase for key '/Users/userz/.ssh/google_compute_engine':

server2輸出:

ssh -v server2
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/userz/.ssh/config
debug1: /Users/userz/.ssh/config line 43: Applying options for server2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to YY.YYY.YYY.YYY [YY.YYY.YYY.YYY] port 22.
debug1: Connection established.
debug1: identity file /Users/userz/.ssh/google_compute_engine type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/userz/.ssh/google_compute_engine-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to YY.YYY.YYY.YYY:22 as 'userz'
debug1: using hostkeyalias: compute.hostkeyaliasY
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
debug1: using hostkeyalias: compute.hostkeyaliasY
debug1: Host 'compute.hostkeyaliasY' is known and matches the ECDSA host key.
debug1: Found key in /Users/userz/.ssh/google_compute_known_hosts:3
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/userz/.ssh/google_compute_engine
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
Password:

在執行以下操作之前,請備份您的~/.ssh/config文件。如果沒有,你可能會過得很糟糕。

這已通過刪除gcloudwith完成的配置來解決

gcloud compute config-ssh --remove

之後,重新安裝執行與問題中所述相同的命令的配置:

gcloud compute config-ssh

這會將實例的別名添加到使用者 SSH 配置 (~/.ssh/config) 文件並更新項目 SSH 元數據。

在經歷了這個之後,我修復了它:

export PROB_INSTANCE='your-instance-name'
gcloud compute ssh another-user@$PROB_INSTANCE

因為~/.ssh/authorized_keys我之前嘗試通過 SSH 訪問的使用者沒有正確設置文件的權限。

但是,YMMV,這對我有用。

引用自:https://serverfault.com/questions/875996