ssh使用public key认证登录

修改/etc/ssh/sshd_config文件:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication no

在~/.ssh/authorized_keys文件末尾添加public key

# cat id_rsa.pub >> ~/.ssh/authorized_keys

重启sshd服务

# service sshd restart

如果使用 public key 登录的时候报错:

$ ssh git@jiya.io
Permission denied (publickey).

解决方法:检查 ~/.ssh/ 目录和 ~/.ssh/authorized_keys 文件的属性, ~/.ssh/ 目录的属性应该为 700~/.ssh/authorized_keys 文件的属性应为 600

# stat -c %a .ssh/
700
# stat -c %a .ssh/authorized_keys
600

家目录的权限应该为700。