生成密钥对
ssh-keygen -t rsa
修改 ssh 配置
# 开启RSA验证
RSAAuthentication yes
# 是否使用公钥验证
PubkeyAuthentication yes
# 公钥的保存位置
AuthorizedKeysFile .ssh/authorized_keys
# 禁止使用密码验证登录
PasswordAuthentication no
复制 ssh 公钥
ssh-copy-id root@192.168.1.10
设置权限
chmod 600 /root/.ssh/authorized_keys
chmod 700 /root/.ssh
使用密钥连接其他主机
ssh -i ~/.ssh/id_rsa root@192.168.1.10 -p 22
# ~/.ssh/id_rsa:私钥路径