Google Cloud Engine。权限被拒绝(publickey,gssapi-keyex,gssapi-with-mic)

时间:2013-12-07 10:08:36

标签: google-compute-engine

我无法通过ssh连接, 我能连接将近24小时。 突然,ssh停止工作。 我有很多用户,我还在该VM中添加了一个新的(tomcat)用户。

当我尝试ssh到我的实例时,我收到以下消息:

"Permission denied (publickey,gssapi-keyex,gssapi-with-mic)."

我最终删除了〜/ .ssh / google_compute_engine *

从Cloud Engine控制台中删除了'sshKeys'元数据

再次尝试gcutil ssh,这会创建新的~/.ssh/google_compute_engine文件以及sshKeys metadata

但我仍然收到了这个错误。

7 个答案:

答案 0 :(得分:5)

我遇到了同样的问题,我调试了大约16个小时。然而,我找到了我希望你在我的奥德赛中分享的解决方案。

我在Google Compute Engine上运行GitLab,宣传为单击安装。

好吧,最后当我尝试克隆私有存储库时,我收到了错误消息:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

我照看了私钥/公钥对,我没有发现任何异常。


然后我认为当我收到调试消息时,服务器上的 sshd 可能有问题:

debug1: ssh_rsa_verify: signature correct
[...]
debug1: Roaming not allowed by server

所以我检查了大量不同的 sshd 设置,但没有解决问题。


最后我开始在服务器端调试并发现错误:

sshd[7364]: debug1: Could not open authorized keys '/var/opt/gitlab/.ssh/authorized_keys': Permission denied

最后,这是幸福的高速公路。因为该文件已存在且 sshd 知道必须加载哪个文件。但是,某种方式存在权限问题

所以我检查了远程 .ssh文件夹中文件的 chmod 是否正常。我没有发现任何异常。


这是解决方案:

SELinux 确实对.ssh文件夹的位置有疑问,并且不愿意授予 ssh守护程序的权限。 通过执行命令

restorecon -Rv /var/opt/gitlab/.ssh/

semanage fcontext -a -t ssh_home_t "/var/opt/gitlab/.ssh/authorized_keys"

其中一个命令解决了这个问题。如果有人可以验证这两者中的哪一个,我会很高兴的!

因此您无需停用 SELinux

答案 1 :(得分:5)

这确实是 @sxleixer 对正确解决方案的评论,但我想要格式化。

  1. 默认情况下未安装semanage工具。去拿

    sudo yum -y install policycoreutils-python
    
  2. 允许非标准的ssh_home_t

    sudo semanage fcontext -a -t ssh_home_t "/var/opt/gitlab/.ssh/authorized_keys"
    
  3. 重启sshd或使用

    完全重启
    sudo shutdown -r now
    
  4. 测试一切在本地工作

    ssh-keygen -t rsa -C "test@example.com"
    cat ~/.ssh/id_rsa.pub # Copy-paste the key to the 'My SSH Keys' section under the 'SSH' tab in your user profile
    ssh -T git@localhost  # Should now output "Welcome to GitLab"
    
  5. 这修复了GitLab在Google Compute Engine上的单击安装。

    确实没有理由关闭SELinux。

答案 2 :(得分:2)

在这种情况下,主用户的.ssh/authorized_keys文件可能配置错误。该文件可能包含错误的数据,但我怀疑您确实需要修复权限。试试这个:

gcutil ssh --ssh_user=anotheruser <yourinstance>
sudo su - <youruser>
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

然后尝试再次以用户身份登录。

答案 3 :(得分:0)

关闭selinux。

setenforce 0

还在/ etc / selinux / config中将SELINUX设置为允许。

然后请回答:https://stackoverflow.com/a/24212432/162070

答案 4 :(得分:0)

解决方案:

  1. 将您的私钥权限更改为实例1上的0600
  2. ssh -i /home/user/.ssh/id_rsa user2@instance-2

答案 5 :(得分:0)

我尝试了以上所有操作,但仍收到此错误消息。

这是新的CentOS 8 VM。我使用CentOS 7 VM没问题,它可以正常工作,并且可以继续工作,但是问题似乎出在CentOS 8上。

我在此处提供了完整的信息和日志(这可能是与此处不同的问题,但这是相同的错误消息):

https://stackoverflow.com/questions/58430955/ssh-stops-working-on-centos-8-gce-vm-permission-denied-publickey-gssapi-keyex

GCE在这里确实出错了,在过去的5年多的时间里这种情况似乎一直在发生,该页面的观看次数超过13000。

答案 6 :(得分:0)

尝试执行此操作,我遇到了相同的问题,以下解决方案效果很好。 使用vi / vim或任何其他编辑器在系统上编辑“ / etc / ssh / sshd_config”文件,并将“ PasswordAuthentication”设置为yes

相关问题