部署测试环境时经常在两台服务器间copy文件,那么如何设置免密登录?

场景:源服务器A(如172) -> 目标服务器B(如71)  实现将服务器A的文件copy到服务器B

实现方式有两种:

在源服务器A(172)上执行:若两台服务期间已设置免密登录(绿色字体是设置免密登录),那么只需要执行下述红色命令

首先运行命令 ssh-keygen  根据提示一路回车即可
[yyuser@hlyy .ssh]$ ssh-copy-id [email protected]
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/yyuser/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: Number of key(s) added: Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added. [yyuser@hlyy home]$ ll
total
-rw-r--r-- root root Sep : a.txt
drwx------ yyuser yyuser Sep : yyuser
[yyuser@hlyy home]$ scp -r a.txt [email protected]:/home/py
a.txt % .0KB/s :

在目标服务器B(71)上执行:若两台服务期间已设置免密登录(绿色字体是设置免密登录),那么只需要执行下述红色命令

首先执行命令ssh-keygen 根据提示一路回车即可
[chenjl@ipha-dev71- .ssh]$ ssh-copy-id [email protected] #将公钥添加到172
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/chenjl/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
/home/yyuser/osinfo.sh: line : lspci: command not found Number of key(s) added: Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added. [chenjl@ipha-dev71- .ssh]$ scp [email protected]:/home/a.txt /home/py
/home/yyuser/osinfo.sh: line : lspci: command not found
a.txt
05-11 15:50