shell script command to solve the SCP-free dense Login

Scenario: transfer files between a remote server

Two free secret server login

A cluster of four servers

A IP
A 47.110.129.242
B 172.16.214.209
C 172.16.214.251
D 172.16.214.251

Generating a public and private key file server
generates the key pair (Run the following commands on the host A id_rsa, id_rsa.pub ):

ssh-keygen -t rsa

The implementation process will remain after the results press Enter to execute:
Here Insert Picture Description
the copy /home/user_01/.ssh/id_rsa.pub A service public key file corresponding to the service B .shh directory and modify the file name authorized_keys

 scp -P 22033  /home/user_01/.ssh/id_rsa.pub  [email protected]:/home/user_01/.ssh/authorized_keys.pub

Need to enter a password server
C, D service file replication service common key B is repeated, with reference to the above instruction

2. Verify successful
repeat the above file scp command does not require a password

Two editions shell script
  1. Create a file to transfer files scp.sh
touch scp.sh
  1. Edit the file
vim scp.sh
scp -P 22033  /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/

scp -P 22033  /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/
scp -P 22033  /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/
  1. Grant execute permissions to the file scp.sh
chmod 777 scp.sh
  1. The last execution sh file
./scp.sh
Published 10 original articles · won praise 9 · views 448

Guess you like

Origin blog.csdn.net/weixin_43829047/article/details/104650519