1.环境

假设本地主机:10.10.10.47
目标主机地址:10.10.10.41

2.本地主机生成密钥

ssh-keygen

3.本地主机会生成密钥文件

id_rsa是私钥 :本地保存,用于匹配
id_rsa.pub是公钥:用于远程分发

4.查找目标主机存放公钥文件

more /etc/ssh/sshd_config

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile.ssh/authorized_keys

5.把本地主机公钥分发到需要通信的目标主机

ssh-copy-id -i ~/.ssh/id_rsa.pub 登录名@10.10.10.41

6.免密指定端口登录

ssh -p 1522 root@xxx.xxx.xxx.xxx
rsync -avzH -e "ssh -p 1522" id_rsa.pub root@xxx.xxx.xxx.xxx