部署測試環境時經常在兩台服務器間copy文件,那么如何設置免密登錄?
場景:源服務器A(如172) -> 目標服務器B(如71) 實現將服務器A的文件copy到服務器B
實現方式有兩種:
在源服務器A(172)上執行:若兩台服務期間已設置免密登錄(綠色字體是設置免密登錄),那么只需要執行下述紅色命令
首先運行命令 ssh-keygen 根據提示一路回車即可 [yyuser@hlyy .ssh]$ ssh-copy-id chenjl@10.1.1.71 /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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys chenjl@10.1.1.71's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'chenjl@10.1.1.71'" and check to make sure that only the key(s) you wanted were added. [yyuser@hlyy home]$ ll total 4 -rw-r--r-- 1 root root 0 Sep 2 23:59 a.txt drwx------ 10 yyuser yyuser 4096 Sep 2 17:22 yyuser [yyuser@hlyy home]$ scp -r a.txt chenjl@10.1.1.71:/home/py a.txt 100% 0 0.0KB/s 00:00
在目標服務器B(71)上執行:若兩台服務期間已設置免密登錄(綠色字體是設置免密登錄),那么只需要執行下述紅色命令
首先執行命令ssh-keygen 根據提示一路回車即可 [chenjl@ipha-dev71-1 .ssh]$ ssh-copy-id yyuser@10.1.1.172 #將公鑰添加到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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys yyuser@10.1.1.172's password: /home/yyuser/osinfo.sh: line 17: lspci: command not found Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'yyuser@10.1.1.172'" and check to make sure that only the key(s) you wanted were added. [chenjl@ipha-dev71-1 .ssh]$ scp yyuser@10.1.1.172:/home/a.txt /home/py /home/yyuser/osinfo.sh: line 17: lspci: command not found a.txt