Use SCP without entering a password to transfer files under Linux

Source: Internet
Author: User
Tags scp command


Recently found a very scary thing, backup server in the backup directory there is no backup files, carefully look at the original SCP command requires a password problem. Prior to establishing a trust relationship, it may be because the root password has been modified, not successful. The following is the specific operation.
Usually use the SCP command through SSH to obtain the other side of the Linux host files need to enter the password confirmation, but by establishing a trust relationship, can be implemented without entering the password.

This assumes the ip:192.168.0.1 of the server S that needs to be backed up
ip:192.168.0.2 for server B as a backup

Need to copy files from a password-free input to B.


1. Execute the following command on server S to generate the pairing key:
SSH-KEYGEN-T RSA
Follow the instructions, note, do not enter passphrase, because I have been operating before, so also prompted whether to overwrite, enter "Y" return on it. Additional information is as follows
Generating public/private RSA key pair.
Enter file in which to save the key (/ROOT/.SSH/ID_RSA):
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b [email protected]

2. Copy the Id_rsa.pub file from the/root/.ssh/directory to the/root/.ssh/directory in Server B and rename it to Authorized_keys.
SCP. ssh/id_rsa.pub [Email Protected]:/root/.ssh/authorized_keys

You will not need a password later from server S SCP to server B.

3. Use this method to be aware that the two computers you are replicating need to use the same account name, and this is where root is used. For security purposes, you need to create the same account on both machines, then switch to the account with the SU command on the server S, then perform step 1th, the ~/.ssh/directory does not exist when copying files in step 2nd, and it needs to be created manually.

In the 2nd step, if the Authorized_keys file already exists in the machine, it is important to note that this file can contain multiple SSH authentication information, then the Cat >> command will be used to append the contents of the verification file.

Now execute script on server S SCP ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/s.pub

Then perform cat ~/.ssh/s.pub >> ~/.ssh/authorized_keys on server B

Finally, you can try it with a small text file.
Execute on server S
Touch ~/test
SCP ~/test [Email protected]:/root/

On server B with LS to see if the success, actually just on the server S on the implementation of the SCP has been prompted to transmit successfully.

Use SCP without entering a password to transfer files under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.