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

Rez*_*azi 4 google-compute-engine

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

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

"Permission denied (publickey,gssapi-keyex,gssapi-with-mic)."
Run Code Online (Sandbox Code Playgroud)

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

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

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

但我仍然得到了这个错误.

sxl*_*xer 5

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

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

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

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Run Code Online (Sandbox Code Playgroud)

我照看私钥/公钥对,我发现没什么不寻常的.


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

debug1: ssh_rsa_verify: signature correct
[...]
debug1: Roaming not allowed by server
Run Code Online (Sandbox Code Playgroud)

所以我检查了大量不同的sshd设置,但没有真正解决这个问题.


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

sshd[7364]: debug1: Could not open authorized keys '/var/opt/gitlab/.ssh/authorized_keys': Permission denied
Run Code Online (Sandbox Code Playgroud)

最后,这是幸福的高速公路.因为文件存在而sshd知道它必须加载哪个文件.但是,某种程度上存在许可问题.

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


这是解决方案:

SELinux确实遇到了.ssh文件夹位置的问题,并且不愿意为ssh守护程序授予权限.通过执行命令

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

要么

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

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

所以你不需要停用SELinux!


Ale*_*ski 5

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

  1. semanage默认情况下不安装该工具.去吧

    sudo yum -y install policycoreutils-python
    
    Run Code Online (Sandbox Code Playgroud)
  2. 允许非标准的ssh_home_t

    sudo semanage fcontext -a -t ssh_home_t "/var/opt/gitlab/.ssh/authorized_keys"
    
    Run Code Online (Sandbox Code Playgroud)
  3. 重启sshd或重启完全重启

    sudo shutdown -r now
    
    Run Code Online (Sandbox Code Playgroud)
  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"
    
    Run Code Online (Sandbox Code Playgroud)

这修复了GitLab在Google Compute Engine上的单击安装.

确实没有理由关闭SELinux.


Ben*_*son 3

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

gcutil ssh --ssh_user=anotheruser <yourinstance>
sudo su - <youruser>
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

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