Enable SCP without entering a password

Source: Internet
Author: User
Sometimes we use SCP when copying/moving files to another machine, because it is safer. However, if

It is annoying to enter passwords, especially in scripts. However, SSH has another key pair for verification.

. The following describes how to generate a key pair for your reference.

Step 1: generate a key pair. I use the RSA key. Run the command "ssh-keygen-t rsa"
[User1 @ RH user1] $ ssh-keygen-T RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/home/user1/. Ssh/id_rsa ):
Created directory '/home/user1/. Ssh '.
Enter passphrase (empty for no passphrase ):
Enter same passphrase again:
Your identification has been saved in/home/user1/. Ssh/id_rsa.
Your public key has been saved in/home/user1/. Ssh/id_rsa.pub.
The key fingerprint is:
E0: F0: 3B: D3: 0a: 3D: da: 42: 01: 6a: 61: 2f: 6C: A0: C6: E7 user1@rh.test.com
[User1 @ RH user1] $
Copy code

During the generation process, the system prompts you to enter the key pair storage location and press enter to accept the default value. Next, you will be prompted to enter 1.

Password different from your password. Press enter to leave it empty. You can also enter one. (I'm lazy.

You do not want to enter the password every time .) In this way, the key pair is generated.

The Public Key is stored in ~ /. Ssh/id_rsa.pub
Private keys are stored in ~ /. Ssh/id_rsa

Then change the. Ssh directory permission and run the command "chmod 755 ~ /. Ssh"
[User1 @ RH user1] $ chmod 755 ~ /. SSH
[User1 @ RH user1] $
Copy code

Copy the public key in this key pair to the machine you want to access and save it

~ /. Ssh/authorized_keys.
[User1 @ RH user1] $ SCP ~ /. Ssh/id_rsa.pub Rh1:/home/user1/. Ssh/authorized_keys
User1 @ Rh1's password:
Id_rsa.pub 100% 228 3.2 MB/S
[User1 @ RH user1] $
Copy code

In this way, we are done. Then, when you access the machine using ssh scp sftp or another type, you do not need to enter a password.

It is more convenient to use on scripts.

From http://bbs.chinaunix.net/viewthread.php? Tid = 343905 & extra = Page % 3d17% 26 filter % 3 ddigest

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.