A本机, B远程服务器.

在A生成公钥:

ssh-keygen -t rsa

生成后用scp指令把 .ssh/id_rsa.pub 复制到远程服务器:

scp .ssh/id_rsa.pub serverip:/root/

连接到远程服务器B:

将id_rsa.pub 添加到.ssh/authorized_keys :

cat id_rsa.pub >> .ssh/authorized_keys

更改权限:

chmod 600 .ssh/authorized_keys

配置完毕。本机A可以免密码访问服务器B。