SSH登录报错Permission denied (publickey)

1、SSH安装,过程略
2、SSH配置 

vi /etc/ssh/sshd_config
port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
KeyRegenerationInterval 3600
RSAAuthentication yes
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 600
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile      %h/.ssh/authorized_keys
IgnoreRhosts yes
HostbasedAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
MaxStartups 20
Subsystem       sftp   /usr/libexec/openssh/sftp-server

3、在home目录下的 .ssh/authorized_keys 添加客户端的公钥信息
4、查看日志记录, 可能存在以下提示(根据日志写入位置不通,可能采用以下3)
tail -f  /var/log/audit/audit.log  

tail -f /var/log/message 
tail -f /var/log/secure
Aug  4 16:29:19 TEST sshd[328]: Authentication refused: bad ownership or modes for directory /root/
Aug  4 16:29:19 TEST sshd[328]: Authentication refused: bad ownership or modes for directory /root/.ssh

5、解决问题,根据提示的文件夹位置,修改对应的文件夹访问权限
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
注意第一条,如果你的HOME目录被设置为其它用户和组用户可以写,那么即时你更改了 .ssh 目录和authorized_keys
文件也解决不了问题!

你可能感兴趣的:(SSH登录报错Permission denied (publickey))