【Linux】Ubuntu设置SSH免密码登录

设置pc1上的user1免密码登录pc2上的user2.

1. 产生加密公钥私钥对:

[user1@pc1 ~]$ 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:
39:f2:fc:70:ef:e9:bd:05:40:6e:64:b0:99:56:6e:01 user1@pc1
The key's randomart image is:
+--[ RSA 2048]----+
|          Eo*    |
|           @ .   |
|          = *    |
|         o o .   |
|      . S     .  |
|       + .     . |
|        + .     .|
|         + . o . |
|          .o= o. |
+-----------------+

2. 此时会在/home/user1/.ssh目录下生成密钥对:

[user1@pc1 ~]$ ll .ssh
总用量 16
drwx------  2 usera usera 4096  8月 24 09:22 .
drwxrwx--- 12 usera usera 4096  8月 24 09:22 ..
-rw-------  1 usera usera 1675  8月 24 09:22 id_rsa
-rw-r--r--  1 usera usera  399  8月 24 09:22 id_rsa.pub

3.user1@pc1的公钥上传到user2@pc2,保存路径为/home/user2/.ssh/authorized_keys.

[user1@pc1 ~]$ ssh-copy-id [email protected]
The authenticity of host '10.124.84.20 (10.124.84.20)' can't be established.
RSA key fingerprint is f0:1c:05:40:d3:71:31:61:b6:ad:7c:c2:f0:85:3c:cf.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.124.84.20' (RSA) to the list of known hosts.
[email protected]'s password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:
 
  .ssh/authorized_keys
 
to make sure we haven't added extra keys that you weren't expecting.

4.user1@pc1免密码登录user2@pc2.

ssh [email protected]
发布了68 篇原创文章 · 获赞 27 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/RadiantJeral/article/details/102787636