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.