一、原理html
登陆的客户端要有私钥,被登陆的服务器要保存客户端生成的公钥。服务器
二、修改服务器/etc/ssh/sshd_config设置,以下:ssh
sudo vi /etc/ssh/sshd_configpost
Protocol 2spa
UsePAM norest
RSAAuthentication yeshtm
PubkeyAuthentication yesblog
保存修改后,执行以下命令重启ssh服务:io
sudo systemctl restart sshd.serviceclass
三、客户端产生一对钥匙。
命令说明:ssh-copy-id把本地主机的公钥复制到远程主机的~/.ssh/authorized_keys文件上。
例子:执行以下命令:
ssh-keygen -t rsa #默认会在~/.ssh生成两个文件
ssh-copy-id -p 58585 -i ~/.ssh/id_rsa.pub root@192.168.0.3