1.客户端生成密钥

ssh-keygen

2.将公钥copy到服务器

ssh-copy-id root@IP地址

之后会让输入服务器的登陆密码

3.登陆服务器

ssh root@IP地址

4.修改文件

vi /etc/ssh/sshd_config

  PubkeyAuthentication yes

  AuthorizedKeysFile .ssh/authorized_keys

  PasswordAuthentication no

  命令模式下搜索:/搜索的字符串

5.重启sshd服务

systemctl restart sshd.service