git私人服务器错误:“权限被拒绝(publickey)”。

我遵循这里的说明,以便在我的Amazon EC2实例上build立一个私有的git服务器。 但是,当我尝试SSH到git帐户时遇到问题。 具体来说,我得到错误“权限被拒绝(公钥)”。

以下是我在EC2服务器上的文件/文件夹的权限:

drwx------ 4 git git 4096 Aug 13 19:52 /home/git/ drwx------ 2 git git 4096 Aug 13 19:52 /home/git/.ssh -rw------- 1 git git 400 Aug 13 19:51 /home/git/.ssh/authorized_keys 

这里是我自己的电脑上的文件/文件夹的权限:

 drwx------ 5 CYT staff 170 Aug 13 14:51 .ssh -rw------- 1 CYT staff 1679 Aug 13 13:53 .ssh/id_rsa -rw-r--r-- 1 CYT staff 400 Aug 13 13:53 .ssh/id_rsa.pub -rw-r--r-- 1 CYT staff 1585 Aug 13 13:53 .ssh/known_hosts 

/var/log/secure检查日志时,每次尝试SSH时都会收到以下错误消息:

 Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys 

但是,在做了一些权限更改之后,我不再收到此错误消息。 尽pipe如此,我仍然得到“权限被拒绝(publickey)”。 每次我尝试SSH的消息。

我用来SSH的命令是ssh -T git@my-ip

这里是我运行ssh -vT [email protected]时得到的完整日志ssh -vT [email protected]

 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 my-ip [my-ip] port 22. debug1: Connection established. debug1: identity file /Users/CYT/.ssh/id_rsa type -1 debug1: identity file /Users/CYT/.ssh/id_rsa-cert type -1 debug1: identity file /Users/CYT/.ssh/id_dsa type -1 debug1: identity file /Users/CYT/.ssh/id_dsa-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.2 debug1: match: OpenSSH_6.2 pat OpenSSH* debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr [email protected] none debug1: kex: client->server aes128-ctr [email protected] 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 08:ad:8a:bc:ab:4d:5f:73:24:b2:78:69:46:1a:a5:5a debug1: Host 'my-ip' is known and matches the RSA host key. debug1: Found key in /Users/CYT/.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: /Users/CYT/.ssh/id_rsa debug1: Trying private key: /Users/CYT/.ssh/id_dsa debug1: No more authentication methods to try. Permission denied (publickey). 

我已经花了几个小时在包括SO和SF在内的各种网站上寻找解决scheme。 看来我的文件的权限都可以,但我无法弄清楚问题所在。 任何帮助将不胜感激。

编辑:

EEAA:以下是您所要求的输出:

 $ getent passwd git git:x:503:504::/home/git:/bin/bash $ grep ssh ~git/.ssh/authorized_keys | wc -l grep: /home/git/.ssh/authorized_keys: Permission denied 0 

我应该更仔细地检查日志。 我的SSH密钥的位置没有正确指定。 我使用SSH -i指定正确的目录,并能够成功通过SSH。

这个错误

 Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys 

通常意味着沿着path链的权限是这样的,不仅根和服务器端用户('git')可以改变/home/git/.ssh/authorized_keys,而且也改变其他人。

每当我看到这个错误,事实certificate,authorized_keys文件本身或其父目录之一是例如组或全局可写的。 你列出了/home/git/.ssh和/ home / git的perms,但是没有列出/ home和/!

您可以通过设置“StrictModes = no”服务器端来放宽这个要求,请参阅sshd_config(5)

这是问题的线:

 -rw-r--r-- 1 CYT staff 400 Aug 13 13:53 .ssh/id_rsa.pub 

你的id_rsa.pub是公共可读的,它不会。 只需chmod 600 .ssh/id_rsa.pub就可以了。