1. 修改/etc/ssh/sshd_config文件:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication no
  1. ~/.ssh/authorized_keys文件末尾添加public key
# cat id_rsa.pub >> ~/.ssh/authorized_keys
  1. 重启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