首頁 > 軟體

Linux下設定SSH無秘鑰登入

2020-06-16 17:10:43

所謂公鑰登入,就是使用者將自己的公鑰儲存在遠端主機上。登入的時候遠端主機回向使用者傳送一段隨機字串,使用者用自己的秘鑰加密後再傳送給遠端主機。遠端主機用事先儲存的公鑰進行解密,如果成功,就證明使用者是可信的,直接允許登入shell,不再要求密碼。

[Hadoop@hadoop01 ~]$ cd .ssh
[hadoop@hadoop01 .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[hadoop@hadoop01 .ssh]$ rm -rf ./*  #清空資料夾
[hadoop@hadoop01 .ssh]$ ssh-keygen -t rsa  #生成公鑰和秘鑰
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
a2:78:65:72:49:9a:71:91:aa:8f:3b:3e:a8:b3:74:87 hadoop@hadoop01.zjl.com
The key's randomart image is:
+--[ RSA 2048]----+
|      ..        |
|      ..        |
|    ..o          |
|    .* .        |
|  .+ * S        |
|  ...* .        |
| o.Eo.          |
|+ =.o            |
|++o+            |
+-----------------+
[hadoop@hadoop01 .ssh]$ ll
total 8
-rw-------. 1 hadoop hadoop 1675 Jun 19 23:41 id_rsa  #秘鑰
-rw-r--r--. 1 hadoop hadoop  405 Jun 19 23:41 id_rsa.pub  #公鑰

[hadoop@hadoop01 .ssh]$ ssh-copy-id hadoop02.zjl.com  #將公鑰傳送給遠端主機
The authenticity of host 'hadoop01.zjl.com (192.168.0.131)' can't be established.
RSA key fingerprint is 60:10:35:2f:64:08:bf:82:e5:bc:56:8c:3d:60:18:13.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop01.zjl.com,192.168.0.131' (RSA) to the list of known hosts.
hadoop@hadoop01.zjl.com's password:
Now try logging into the machine, with "ssh 'hadoop01.zjl.com'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[hadoop@hadoop01 .ssh]$ ssh hadoop01.zjl.com  #無密碼登入
 Last login: Mon Jun 19 23:30:46 2017 from 192.168.0.1
[hadoop@hadoop02 ~]$  #無密碼登入成功

下面關於SSH相關的文章您也可能喜歡,不妨參考下:

Ubuntu 下設定 SSH服務全過程及問題解決 http://www.linuxidc.com/Linux/2011-09/42775.htm

Ubuntu 14.04 下安裝Samba 及SSH 伺服器端的方法 http://www.linuxidc.com/Linux/2015-01/111971.htm

叢集環境SSH免密碼登入設定  http://www.linuxidc.com/Linux/2017-03/141296.htm

提高Ubuntu的SSH登陸認證速度的辦法 http://www.linuxidc.com/Linux/2014-09/106810.htm

遠端SSH連線服務與基本排錯  http://www.linuxidc.com/Linux/2017-05/143738.htm

使用SSH公鑰金鑰自動登陸Linux伺服器 http://www.linuxidc.com/Linux/2017-02/140642.htm

開啟SSH服務讓Android手機遠端存取 Ubuntu 14.04  http://www.linuxidc.com/Linux/2014-09/106809.htm

SSH非互動式密碼授權遠端執行指令碼  http://www.linuxidc.com/Linux/2017-04/143180.htm

SSH通過金鑰登陸 http://www.linuxidc.com/Linux/2017-06/144997.htm

Linux上實現SSH免密碼登陸遠端伺服器  http://www.linuxidc.com/Linux/2017-05/144165.htm

本文永久更新連結地址http://www.linuxidc.com/Linux/2017-07/145450.htm


IT145.com E-mail:sddin#qq.com