Linux method of copying files and password free login between two servers
- 2020-05-30 21:44:54
- OfStack
Sometimes to build a cluster machine, you need to copy files from one machine to another. One way is to copy sftp to the machine and then copy it to other servers. Here is a way to copy files directly between two servers and get rid of tedious login operations.
Copy files between two servers
If there are two servers 192.168.129.100/101, now you need to copy the 100/ etc/passwd file to the /etc directory of the 101 server. Log in the 100 server and know that the password of the 101 user root is 123456
scp /etc/passwd root@192.168.129.101:/etc/
The authorization operation will be prompted for the first time. Enter yes and then enter the password of root user. Copy is completed.
Password-free login between servers
Now it is very troublesome to enter the password every time you copy the file. Now I will introduce a way to use public key/private key authentication to remove the password and log in
Enter the.ssh directory on the 100 server,
cd ~/.ssh
ssh-keygen -t rsa
scp id_rsa.pub root@192.168.129.101:~/.ssh
Enter the 101 server and import the public key to ~/.ssh /authorized_keys,
cd ~/.ssh
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
~/.ssh Permission set to 700
~/.ssh/authorized_keys Is set to 600
This is the security requirement of Linux, if the permissions are not correct, the automatic login will not take effect
After that, log out of the server and log in using ssh. You will find that the server will no longer ask you for your password.