linux ssh scp sftp generate key pair

http://blog.csdn.net/hereiskxm/article/details/7861759

(Recommended) Generate a key pair

Because this method does not need to uninstall the key in the program, it is more secure

Step 1: Generate a key pair, I use the rsa key. Use 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 [email protected]
[user1@rh user1]$

During the generation process, you are prompted to enter the storage location of the key pair, just press Enter and accept the default value. Then you will be prompted to enter a password different from your password, just press Enter and leave it blank.
Of course, one can also be entered. (I'm lazy and don't want to have to enter the password every time.) This way, the key pair is generated.

where the public key is kept in ~/.ssh/id_rsa.pub and
the private key is kept in ~/.ssh/id_rsa
Then change the permissions of the .ssh directory and use the command "chmod 755 ~/.ssh"
[user1@rh user1]$ chmod 755 ~/.ssh
 
Then copy the public key in this key pair to the machine you want to access and save it as
~/.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.2MB/s 00:00
[user1@rh user1]$

And that's it. Then when you use ssh scp sftp to access that machine, you don't need to enter the password
Now, it is more convenient to use in script.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939220&siteId=291194637