Password not required for transferring scp via SSH

Source: Internet
Author: User
Tags scp command

SSH transmission of scp does not require a password recently encountered a problem in the preparation of a shell that is scheduled to be automatically executed. In this step, you need to use the scp command to copy the local file to another machine for backup. However, you usually need to enter the user password after executing the scp command, which is not applicable in the shell step of timed Automatic execution. My first instinct is to create a user without a password. To use this user in the scp command, you do not need to enter the user password. For the convenience of discussion, we call the machine that executes the scp command as the Client, and the remote machine operated by the scp command as the Server. First, run the following command to delete the root password on the Server, even if the root password is changed to a user without a password. [Root @ Server root] # passwd-d root Removing password for user root. passwd: Success [root @ Server root] # To confirm that the root user has become a user without a password, log on and try again. Red Hat Linux release 8.0 (Psyche) Kernel 2.4.18-14 on an i686 Server login: root Last login: fri Sep 14 16:40:08 on tty1 [root @ Server root] # It is true that the password is no longer required for root login. Then, we copy a file from the Client to the Server. [Root @ Client root] # scp-p text root@ root@'s password: <-- press ENTER Permission denied, please try again. <-- The root@'s password is denied: <-- enter any character text 100% | ************************** | 19 [root @ client root] # according to the test results, even if the root user is a user without a password, the scp command will prompt you to enter the password during execution. Even more strange is that the press enter is rejected when the password is prompted. However, if you enter any other characters, enter the Enter key to confirm the authentication. Later, I searched for related information on the Internet. For more information, [1] after the two users of the two machines establish a secure trust relationship, you do not need to enter the user password when executing the scp command. Based on the method described in this document, the test is successful. Follow these steps to establish a security trust relationship between the root of the Client and the root of the Server: 1. run the ssh-keygen command on the Client to generate a certificate that establishes a security trust relationship. [Root @ Client root] # ssh-keygen-B 1024-t rsa 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: <-- press Enter to Enter Your identification has been saved in/root /. ssh/id_rsa. your public key has been saved in/root /. ssh/ the key fingerprint is: 49: 9c: 8a: 8f: bc: 19: 5e: 8c: C0: 10: d3: 15: 60: a3: 32: 1c root @ Client [root @ Client root] # Note: When the program prompts passphrase input, press Enter, indicates no certificate password. The above command generates the Private Key Certificate id_rsa and Public Key Certificate, which are stored in the. ssh subdirectory of the user's home directory. 2. Copy the Public Key Certificate to the. ssh subdirectory of the root directory of the Server, and change the file name to authorized_keys. [Root @ Client root] # scp-p. ssh/ root@ /. ssh/authorized_keys root@'s password: <-- enter the root user password of the Server 100% | **************************** | 218 [root @ Client root] # When executing the preceding command, the root user of the two machines has not yet established a security trust relationship, so you also need to enter the root user password of the machine Server. After the above two steps, the security trust relationship is established between the root of the Client and the root of the Server. Next let's look at the effect: [root @ Client root] # scp-p text root@ /root text 100% | ************************* | 19 [root @ Client root] # succeeded! You do not need to enter the password any more.

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: 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.