1、确认本机sshd的配置文件
vim /etc/ssh/sshd_config
找到以下内容,并去掉注释符”#“
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
2、修改了配置文件需要重启sshd服务
service sshd restart
3.生成公钥和私钥
ssh-keygen -t rsa
默认在 ~/.ssh目录生成两个文件:
id_rsa :私钥
id_rsa.pub :公钥
4.导入公钥到认证文件,更改权限
(1)导入本机
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
(2)导入到免密码登录的请求方服务器,比如A要免密码登录B
a.把B的公钥导入到A
scp ~/.ssh/id_rsa.pub xxx@host:/home/id_rsa.pub
b.在服务器A上将公钥导入到认证文件
cat /home/id_rsa.pub >> ~/.ssh/authorized_keys
5.更改文件权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
6.测试
在A上免密码登录B
ssh HostB