gcloud:ssh-ing到服务器时权限被拒绝(公钥)

Posted

技术标签:

【中文标题】gcloud:ssh-ing到服务器时权限被拒绝(公钥)【英文标题】:gcloud: permission denied (public key) when ssh-ing to server 【发布时间】:2018-04-29 05:50:11 【问题描述】:

我正在尝试为 gcloud 实例设置新的 ssh 密钥。我按照此处的说明逐字执行 (https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys),生成一个新密钥,将带有我的用户名的公共 rsa-ssh 密钥放在 Google Cloud Platform 界面中元数据选项卡的 SSH 密钥部分,并为我的使用 chmod 的公钥和私钥。

在尝试使用 -vvv 详细标志进行 ss 时,我收到如下错误:

...

debug1: Next authentication method: publickey debug1: Offering RSA public key: /Users/erickofman/.ssh/salsadb debug3: send_pubkey_test 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 debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey).

我(与同事)确保我的公钥包含在服务器的 .ssh 文件夹中的 authorized_keys 文件中。考虑到某些东西可能已经过时,我还尝试使用service sshd restart 重新启动 ssh 服务器,但无济于事。

我还尝试使用 gcloud 工具设置 ssh,结果相同。

据我所知,我拥有该网站的正确角色/权限。

这是日志在服务器端的样子:

admin@awesome-website:~$ tail /var/log/auth.log Nov 15 20:40:16 awesome-website sshd[18846]: input_userauth_request: invalid user ekofman [preauth] Nov 15 20:40:17 awesome-website sshd[18846]: Connection closed by 10.100.100.10 port 90001 [preauth] Nov 15 20:41:17 awesome-website sshd[18848]: Connection closed by 200.200.20.20 port 90002 [preauth]

一直在努力解决这个问题,非常感谢任何帮助!

【问题讨论】:

“提供 RSA 公钥:/Users/erickofman/.ssh/salsadb.pub”***.com/a/29948797/13317 @Kenster 糟糕,我粘贴了不正确的代码——我在使用私钥时得到了完全相同的错误,但是,我已经更新了帖子 debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: /Users/erickofman/.ssh/salsadb debug3: send_pubkey_test 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 debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey). 是否有其他用户可以使用密钥ssh? 是的,我的同事已经能够使用之前生成并添加的密钥,但是我们从头开始一起完成了相同的过程,现在他无法使用新密钥进行 ssh。 【参考方案1】:

Whelp,事实证明,除非完全重启实例,否则不会合并新的 ssh 密钥。 不是 ssh 服务器重启,而是一个完整的实例重启(停止 gcloud 实例,然后启动 gcloud 实例)。文档中没有这样说,很高兴知道以备将来参考。

【讨论】:

有趣。不要忘记将其标记为答案,***.com/help/self-answer【参考方案2】:

根据this,确保您是您的用户目录中的 .ssh/authorized_keys。

您还需要确保您的 .ssh 目录和 authorized_keys 具有正确的权限集。 (分别为 700 和 600)。

sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/authorized_keys

【讨论】:

谢谢,但是没有用——这两个链接都指向同一个站点——你是不是要为第二个链接发布不同的链接? 我一定弄乱了我的剪贴板。删除了第二个。

以上是关于gcloud:ssh-ing到服务器时权限被拒绝(公钥)的主要内容,如果未能解决你的问题,请参考以下文章

gcloud 组件更新权限被拒绝

Windows 上的 Gcloud 命令(使用 git bash)正在记录错误:WindowsApps/python3:权限被拒绝

尝试运行 bigquery 时 gcloud auth 登录问题 403 访问被拒绝

错误:启动 Dataproc 集群时资源项目的权限被拒绝

容器之间的 Kubernetes 卷 - 权限被拒绝

将文件从一台服务器复制到另一台服务器时权限被拒绝