Google云平台:无法通过SSH连接到计算实例

Google云平台:无法通过SSH连接到计算实例

我无法通过 SSH 连接到我的 GCP 实例。从基于 Web 的控制台通过 SSH 连接没问题,我可以使用笔记本电脑上的 Google Cloud SDK shell 进行连接,这排除了连接或防火墙问题。

我已尝试启用操作系统登录:

在此处输入图片描述

我不太明白这一点,所以我尝试直接添加 SSH 密钥:

在此处输入图片描述

这是我的文件中的公钥部分id_rsa,从 puttygen 复制而来:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3u7O9pk3YtE10hjaRAWixkwAv6rvOIiMnF+KOQyO/MG8GcGKUypL3nNbotmvPu8hlROz/GghkkSxzp3Bubm+8K+K4A8s68tyUenYXZcdN71BOVnY1F23gt9FfwHO5n9M9nQQwwyHtVJtRF7RPPJpD8L3NO1M7YxKSoW10+omEOBhAjo5PS0pcaiaUoh5C9Z0+fpmZPuFEZ43w9MFxt5LPU/46LwoYCvNOGFICAHshpQRsl94v+QzHzAShCvwjPkCryMDFzLdOylIIua94ZlnYNWElSSNZ2nFRHGgbyqhYIYj4IMV1nNrh11bL6PgmW9Dq6pfz2KGrbrBMBJPRSkzZ imported-openssh-key

该注释以我尝试通过 SSH 连接的 theuncated/tail 输出结束,但是我运行了该命令,-vvv所以它很长。

    PS C:\Users\Ian> ssh -vvv ian_newson_gmail_com@[REDACTED]
*SNIP*
    debug2: languages ctos:
    debug2: languages stoc:
    debug2: first_kex_follows 0
    debug2: reserved 0
    debug1: kex: algorithm: curve25519-sha256
    debug1: kex: host key algorithm: ssh-ed25519
    debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
    debug3: send packet: type 30
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug3: receive packet: type 31
    debug1: SSH2_MSG_KEX_ECDH_REPLY received
    debug1: Server host key: ssh-ed25519 SHA256:lA8OfaT+zJSicRoNfgnnkHMofmihr8PcKngqlBObenk
    debug3: record_hostkey: found key type ED25519 in file C:\\Users\\Ian/.ssh/known_hosts:9
    debug3: load_hostkeys_file: loaded 1 keys from [REDACTED]
    debug3: Failed to open file:C:/Users/Ian/.ssh/known_hosts2 error:2
    debug1: load_hostkeys: fopen C:\\Users\\Ian/.ssh/known_hosts2: No such file or directory
    debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
    debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
    debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
    debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
    debug1: Host '[REDACTED]' is known and matches the ED25519 host key.
    debug1: Found key in C:\\Users\\Ian/.ssh/known_hosts:9
    debug3: send packet: type 21
    debug2: set_newkeys: mode 1
    debug1: rekey out after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug3: receive packet: type 21
    debug1: SSH2_MSG_NEWKEYS received
    debug2: set_newkeys: mode 0
    debug1: rekey in after 134217728 blocks
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_rsa RSA SHA256:4RkpcJoekNd71rWzZU8Twwq3svIH9WgoOL35JSh83d8 agent
    debug1: Will attempt key: .\\gcp.openssh.key RSA SHA256:aMIaDYUExt0e4bAlx1+TXLtXFVvgksuGi+R3i5XWVTs agent
    debug1: Will attempt key: .\\ssh.key RSA SHA256:TMEoLGu61in1hlbW8jbAJ94TpmAL+9tbSf4mKMHJ2GQ agent
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_rsa
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_dsa
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_ecdsa
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_ecdsa_sk
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_ed25519
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_ed25519_sk
    debug1: Will attempt key: C:\\Users\\Ian/.ssh/id_xmss
    debug2: pubkey_prepare: done
    debug3: send packet: type 5
    debug3: receive packet: type 7
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
    debug3: receive packet: type 6
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug3: send packet: type 50
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey
    debug3: start over, passed a different list publickey
    debug3: preferred publickey,keyboard-interactive,password
    debug3: authmethod_lookup publickey
    debug3: remaining preferred: keyboard-interactive,password
    debug3: authmethod_is_enabled publickey
    debug1: Next authentication method: publickey
    debug1: Offering public key: C:\\Users\\Ian/.ssh/id_rsa RSA SHA256:4RkpcJoekNd71rWzZU8Twwq3svIH9WgoOL35JSh83d8 agent
    debug3: send packet: type 50
    debug2: we sent a publickey packet, wait for reply
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey
    debug1: Offering public key: .\\gcp.openssh.key RSA SHA256:aMIaDYUExt0e4bAlx1+TXLtXFVvgksuGi+R3i5XWVTs agent
    debug3: send packet: type 50
    debug2: we sent a publickey packet, wait for reply
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey
    debug1: Offering public key: .\\ssh.key RSA SHA256:TMEoLGu61in1hlbW8jbAJ94TpmAL+9tbSf4mKMHJ2GQ agent
    debug3: send packet: type 50
    debug2: we sent a publickey packet, wait for reply
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_rsa
    Enter passphrase for key 'C:\Users\Ian/.ssh/id_rsa':
    debug3: sign_and_send_pubkey: RSA SHA256:4RkpcJoekNd71rWzZU8Twwq3svIH9WgoOL35JSh83d8
    debug3: sign_and_send_pubkey: signing using rsa-sha2-512 SHA256:4RkpcJoekNd71rWzZU8Twwq3svIH9WgoOL35JSh83d8
    debug3: send packet: type 50
    debug2: we sent a publickey packet, wait for reply
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_dsa
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_dsa: No such file or directory
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_ecdsa
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_ecdsa: No such file or directory
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_ecdsa_sk
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_ecdsa_sk: No such file or directory
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_ed25519
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_ed25519: No such file or directory
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_ed25519_sk
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_ed25519_sk: No such file or directory
    debug1: Trying private key: C:\\Users\\Ian/.ssh/id_xmss
    debug3: no such identity: C:\\Users\\Ian/.ssh/id_xmss: No such file or directory
    debug2: we did not send a packet, disable method
    debug1: No more authentication methods to try.
    ian_newson@[REDACTED]: Permission denied (publickey).

以下是 mu 的一些输出/var/log/auth.log

Apr 13 19:17:01 instance-1 CRON[12310]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 13 19:17:01 instance-1 CRON[12310]: pam_unix(cron:session): session closed for user root
Apr 13 19:21:43 instance-1 sshd[12322]: Connection reset by authenticating user ian_newson [REDACTED] port 65262 [preauth]
Apr 13 19:21:47 instance-1 sudo: pam_unix(sudo:session): session closed for user root
Apr 13 19:21:49 instance-1 sudo: ian_newson_gmail_com : TTY=pts/1 ; PWD=/home/ian_newson_gmail_com ; USER=root ; COMMAND=/usr/bin/nano /var/log/auth.log
Apr 13 19:21:49 instance-1 sudo: pam_unix(sudo:session): session opened for user root by ian_newson_gmail_com(uid=0)

答案1

我通过使用 gcloudsdk 并用 来监控它来解决了这个问题procmon

首先使用 gcloud SDK 创建 SSH 连接:

例如ssh instance-1 --zone=us-central1-a

这将创建一个名为的文件。使用 PuttyGen 打开此文件,并通过单击>“导出 OpenSSH 密钥”~/.ssh/google_compute_engine.ppk使用它来创建 OpenSSH 密钥。Conversions

该文件可用于使用 连接到实例ssh -i {filename} {username}@{host}

相关内容