生成Key
$ ssh-keygen -t rsa -b 4096 -C “your_email@domain.com”
$ cd ~/.ssh && ls -l ~/.ssh/id_*.pub
传送key到server
$ ssh-copy-id root@server_ip_address
取消密码登陆
$ ssh root@server_ip_address
$ vim /etc/ssh/sshd_config
找到下面并改成这样
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
$ systemctl restart ssh
以后直接ssh root@server_ip_address 输入密码就可以登陆服务器了,注意:密码别忘了,key要备份。