NEO*_*NEO 35 debian ssh ssh-keys google-compute-engine google-cloud-platform
我通过 Google Compute Engine 中的 Bitnami 创建了一个 VM。以前,我可以通过 Bitnami Web 界面进行 ssh。我试图通过 Mac 上的终端 ssh,但一直收到Permission denied (publickey)错误消息。然后我删除了服务器和我的 Mac 上的所有密钥,并从 bitnami 下载了 pem 文件并使用-i了连接选项,但问题仍然存在。
ssh -i bitnami-gce.pem xxx@1xx.1xx.5x.1xx -v
Run Code Online (Sandbox Code Playgroud)
完整的调试信息:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 1xx.1xx.5x.1xx [1xx.1xx.5x.1xx] port 22.
debug1: Connection established.
debug1: identity file bitnami-gce.pem type -1
debug1: identity file bitnami-gce.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Debian-4~bpo70+1
debug1: match: OpenSSH_6.6.1p1 Debian-4~bpo70+1 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA <RSA KEY>
debug1: Host '1xx.1xx.5x.1xx' is known and matches the RSA host key.
debug1: Found key in /Users/xxx/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: bitnami-gce.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
我无法通过 ssh 连接到主机。所以现在不能向服务器发送任何密钥。如何解决这个问题?
编辑:我尝试通过 Google 网络控制台 ssh,我可以做到。谁能告诉我从任何地方 ssh 的确切步骤?我更喜欢简单的用户名和密码方式,如何配置它?
NEO*_*NEO 26
在我能够通过 Google Web 控制台 ssh 之后,我执行了以下步骤来解决这个问题:
使用生成 ssh 密钥
ssh-keygen
复制 key.pub 文件内容
将内容附加到~/.ssh/authorized_keys文件中
sudo nano ~/.ssh/authorized_keys
小智 14
由于用户,我面临同样的情况。在 google web shh 上,我的用户名显示了我电子邮件的第一部分。所以,我像这样尝试 ssh
ssh <first_part_of_gmail>@google_vm_external_ip
Run Code Online (Sandbox Code Playgroud)
后来,我发现,google 根据您放在 google vm 设置上的 ssh 密钥创建了一个用户。因此,首先检查公钥末尾的用户,然后尝试以下操作
ssh <user_name_at_the_end_of_public_key>@google_vm_external_ip
Run Code Online (Sandbox Code Playgroud)
如果您在实例上使用 OS Login 管理 SSH 密钥,则这些实例上基于元数据的 SSH 密钥配置将被禁用
和
注意:在实例上启用 OS Login 会在这些实例上禁用基于元数据的 SSH 密钥配置。禁用 OS Login 会恢复您在项目或实例元数据中配置的 SSH 密钥。
要进行验证,请转到项目级元数据(Compute Engine -> Metadata)并确保您没有enable-oslogin密钥或将其设置为FALSE
首次创建您的实例时,默认情况下它不会包含任何 SSH 密钥,因此您必须将它们传输到那里,例如,gcloud按照此 SO 答案中的描述第一次使用连接到它,或者手动创建 SSH 密钥并按照另一个 SO 答案中的描述手动将它们添加到您的实例中。