Practical Tips for saving SSH passwords in Linux

Source: Internet
Author: User
Article Title: practical tips for saving SSH passwords in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Scp is used when copying/moving files from one machine to another, because it is safer. However, it is annoying to enter a password every time, especially in scripts. However, ssh has another key pair verification method. 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

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 a password different from your password. Press enter to leave it empty. You can also enter a key pair to generate the key pair.

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

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] $

It's done. Then you can use ssh scp sftp to access the machine without entering the password. It is more convenient to use it on scripts.

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.