SSH公钥不起作用

更新:我已经解决了这个奇怪的问题,只需重新启动sshd 。 不过,我仍然想知道为什么,因为服务器启动后我没有更改任何configuration。

我有2个服务器,一个安装了CentOS 5,另一个是CentOS 6. ssh publickey在CentOS 5上运行正常,但在CentOS 6上不能运行。我确认了.ssh目录的权限,没关系。

 [root@localhost ~]# ls -Z .ssh/ drwxr-xr-x. root root unconfined_u:object_r:ssh_home_t:s0 . dr-xr-x---. root root system_u:object_r:admin_home_t:s0 .. -rw-r--r--. root root unconfined_u:object_r:ssh_home_t:s0 authorized_keys -rw-------. root root unconfined_u:object_r:ssh_home_t:s0 id_rsa -rw-r--r--. root root unconfined_u:object_r:ssh_home_t:s0 id_rsa.pub -rw-r--r--. root root unconfined_u:object_r:ssh_home_t:s0 known_hosts 

更新:我已经尝试了几个权限,其中包括600,644的authorized_keys和700,755的.ssh/ ,所有这些都不起作用。

ssh -vvv给出这些消息

 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: /Users/zuohaocheng/.ssh/id_rsa debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Trying private key: /Users/zuohaocheng/.ssh/id_dsa debug3: no such identity: /Users/zuohaocheng/.ssh/id_dsa debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: ,password debug3: authmethod_is_enabled password debug1: Next authentication method: password 

sshd_config所有内容都是默认值。 另外,我通过ssh-copy-id复制了publickey。

您对authorized_keys权限不正确。 您应该取消对群组和其他人的读取权限。

目录/文件权限应如下所示:

 chmod 700 ~/.ssh chmod 644 ~/.ssh/authorized_keys chmod 644 ~/.ssh/known_hosts chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub 

ls -l ~/.ssh显示你的chmod权限。 检查是否启用了PermitRootLogin Yes ,因为您正在复制在根目录的.ssh目录中生成的pub key。 这可能会产生问题。

~/ (你的主目录)有什么权限? 你不能在任何级别允许别人覆盖你的~/.ssh目录的权限。 如果您的主目录比755更宽容,则会提示您input密码。

如果你正在运行selinux,那可能是问题所在。 .ssh目录的types和下面的文件应该是ssh_home_t。 您可以使用ls -Z进行validation,并使用restorecon -Rv .ssh进行还原。

/ var / log / secure也可能有更详细的错误信息。

授权密钥的权限必须为600才能进行公钥authentication。

我遇到了同样的问题,事实certificate,这与我将我的主目录移动到另一个磁盘(出于空间原因)的事实有关,并且默认的安全设置不喜欢这个新的地方,因此不能或不会find我的.ssh目录。 试图找出更新ssh_home_t设置。