Using SCP in Linux does not require a password to transfer files

Source: Internet
Author: User
Tags scp command ssh server

Using SCP in Linux does not require a password to transfer files

I suddenly found that there was no backup file in the backup directory on the backup server. I checked it carefully and found that the scp command required a password. I have previously established a trust relationship. It may be because I have modified the root password and it cannot be successful. The following describes how to use SCP in Linux to transfer files without entering a password.

Generally, when you use the scp command to obtain the file of the other Linux host through ssh, you need to enter the password for confirmation. However, by establishing a trust relationship, you can do not enter the password.

Assume that the IP address of the server S to be backed up is 192.168.0.1.
IP address of server B used for backup: 192.168.0.2

Copy the file from A without A password to B.

1. Execute the following command on server S to generate a pair key:
Ssh-keygen-t rsa
Follow the prompts. Note that do not enter passphrase. Because I have already performed this operation, I have also indicated whether to overwrite it. Enter "y" and press Enter. Other prompts are 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 root@localhost.domain

2. Copy the id_rsa.pub file in the/root/. ssh/directory to the/root/. ssh/directory of server B and change it to authorized_keys.
Scp. ssh/id_rsa.pub root@192.168.0.2:/root/. ssh/authorized_keys

In the future, the password will not be required from the server S scp to server B.

3. When using this method, you must note that the two computers to be copied must use the same account name, and the root account is used here. To ensure security, you need to create the same account on the two machines, switch to the account using the su command on server S, and then execute step 1, when copying a file in step 1 ~ The/. ssh/directory does not exist and needs to be created manually.

If the authorized_keys file already exists in the machine in step 1, you must note that this file can contain multiple SSH authentication information. In this case, you can use the cat> command to append the authentication file content.

Execute the script scp ~ on server S ~ /. Ssh/id_rsa.pub root@192.168.0.2:/root/. ssh/s. pub

Then run cat ~ on server B ~ /. Ssh/s. pub> ~ /. Ssh/authorized_keys

Finally, you can try it with a small text file.
Run
Touch ~ /Test
Scp ~ /Test root@192.168.0.2:/root/

Use ls on server B to check whether the transfer was successful. In fact, the transfer was successful when scp was executed on server S.

You may also like the following SSH-related articles. For details, refer:

Complete SSH service configuration and troubleshooting in Ubuntu

How to install Samba and SSH server in Ubuntu 14.04

SSH service remote access to Linux Server login is slow

How to Improve the SSH login authentication speed of Ubuntu

Enable the SSH service to allow Android phones to remotely access Ubuntu 14.04

How to add dual authentication for SSH in Linux

Configure the SFTP environment for non-SSH users in Linux

Configure and manage the SSH service on Linux

This article permanently updates the link address:

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.