无法获得SSH公钥authentication工作

我的服务器正在运行CentOS 5.3。 我在运行Leopard的Mac上。 我不知道这是谁负责:

我可以通过密码authenticationlogin到我的服务器。 我已经完成了设置PKA的所有步骤(如http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-ssh-beyondshell.html所述 ),但是当我使用SSH,它甚至拒绝公开密钥validation。 使用该命令

ssh -vvv user@host 

(其中-vvv将冗长度转化为最高级别)我得到以下相关输出:

 debug2: key: /Users/me/.ssh/id_dsa (0x123456) debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-with-mic,password debug3: preferred keyboard-interactive,password debug3: authmethod_lookup password debug3: remaining preferred: ,password debug3: authmethod_is_enabled password debug1: Next authentication method: password 

随后提示input密码。 如果我试图强迫这个问题

 ssh -vvv -o PreferredAuthentications=publickey user@host 

我明白了

 debug2: key: /Users/me/.ssh/id_dsa (0x123456) debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-with-mic,password debug3: preferred publickey debug3: authmethod_lookup publickey debug3: No more authentication methods to try. 

所以,即使服务器说它接受publickeyauthentication方法,而我的SSH客户端坚持,我被反驳。 (请注意上面显示的“提供公共密钥:”行的显着缺失。)有什么build议吗?

检查你的Centos机器是否有:

 RSAAuthentication yes PubkeyAuthentication yes 

在sshd_config中

并确保你在centos机器的〜/ .ssh /目录下有适当的权限。

 chmod 700 ~/.ssh/ chmod 600 ~/.ssh/* 

应该做的伎俩。

我有一个类似的问题 – 远程PC不能使用公钥authenticationlogin到CentOs 6服务器。 在我的情况下,问题是SELinux相关的 – 试图login的用户的主目录有安全上下文的消息。 我通过这样使用restorecon工具解决了这个问题:

 restorecon -Rv /home 

1-检查你的/ etc / ssh / sshd_config,确保你有

 RSAAuthentication是
 PubkeyAuthentication yes

2-检查远程机器的安全日志,查看详细的sshd守护进程错误日志。 例如在我的Ubuntu

 #grep'sshd'/ var / log / secure |  grep'authentication被拒绝'| 尾巴-5
 8月4日06:20:22 xxx sshd [16860]:身份validation被拒绝:所有权或目录/ home / xxx的模式
 8月4日06:20:22 xxx sshd [16860]:身份validation被拒绝:所有权或目录/ home / xxx的模式
 8月4日06:21:21 xxx sshd [17028]:身份validation被拒绝:目录/ home / xxx的所有权或模式不正确
 8月4日06:21:21 xxx sshd [17028]:身份validation被拒绝:目录/ home / xxx的所有权或模式不正确
 8月4日06:27:39 xxx sshd [20362]:身份validation被拒绝:目录/ home / xxx的所有权或模式错误

然后检查目录/ home / xxx的所有权和模式,也许你需要运行这个

 chmod 755 / home / xxx

请仔细检查您的权限是否正确,文件结构(特别是拼写)对于本地和远程机器都是正确的。 你引用的URL说明了所有的内容,但值得检查一下你所匹配的内容。 通常权限将会抛出一个相关的错误。

你是否检查过你的CentOS 5.3盒子上的sshd_config设置为允许PubkeyAuthentication或RSAAuthentication?

检查CentOS系统上的SSH服务器日志 – 它可能提供更多的信息。 我不确定CentOS是否列入了被列入黑名单的ssh密钥,但是我已经看到ssh的publickey拒绝了,只要-vvv的输出结果是相对安静的,但是日志很清楚地解释了发生了什么事情

得到它了! 原来这是一个客户端问题。 (我认为任何服务器端问题都会产生更多有用的debugging输出。)由于我不知道的原因,在我的Mac上,文件/ etc / ssh_config有行

 PubkeyAuthentication = no 

我注意到一行,现在一切正常。

除了文件/目录的模式,确保所有权是正确的! 用户必须拥有自己的主目录,.ssh /和其中的文件。

我不得不运行chown -R $user:$user /home/$user来获取我的ssh失败。

还要检查它是否可以自动提供一个密钥,如果不是或者只是为了testing,使用-ipath/到/键

听起来像是一个configuration问题给我。 像丹尼尔build议有两件事情要检查:

  1. $HOME/.ssh/authorized_keys中的SSH密钥是可读的; 和
  2. SSHd被configuration为允许公共密钥login。

ssh -v中,客户端的输出会显示在协议的某个步骤中有问题,但是当由于服务器上的某些事情而导致客户端将不会被告知原因。 检查服务器日志文件以找出错误。 您可能需要成为root才能拥有这样的权限。 例如,对于configuration为login到系统日志的sshd ,您可能会在/var/log/securefind这些消息。 像这些:

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

在这种情况下,原因是(愚蠢的) default0002 。 这意味着,为该组写入访问权限。 (Groupname =用户名,但是仍然是。)SSH守护进程不会信任可能被用户篡改的文件(当然,还有root用户)。 你可以使用chmod来解决这个问题。

 chmod 700 ~/.ssh # solve the issue chmod 720 ~/.ssh # reproduce the issue # or similar for a file 

我只是陷入了同样的问题访问与Fedora的核心16美分5.5

日志和详细看起来完全一样

问题是公钥,它得到了一些假的数据,重新生成它并将其发布到sshd_server中,你sshd_client发送的是密钥信息,但是服务器不能识别它(它匹配了authorized_keys中的任何密钥)

检查你想login的用户名。默认情况下,它是你在本地机器上的用户名。

另一个被这个咬了。 经过长时间的search后,我发现我明确地提供了公钥(使用-i选项)而不是私钥。 卫生署!