環境:
ssh server: 192.168.100.29 server.example.com
ssh client: 192.168.100.30 client.example.com
通過root使用者建立秘鑰認證實現SHELL指令碼管理,分發,部署
首先client端建立秘鑰對,並將公開金鑰分發給需要登入的SSH服務端
註:公開金鑰相當於鎖,私密金鑰相當於鑰匙,我們這裡相當於在用戶端建立一對鑰匙和鎖,想要做到SSH免密碼登入,就相當於我們將鎖分發到服務端並裝鎖,然後用戶端就可以利用鑰匙開鎖。
一.建立秘鑰認證
1.在用戶端建立秘鑰對:(ssh client)
# su - root
# ssh-keygen -t dsa
一路斷行符號即可
----------------------
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
e9:5e:4a:7f:79:64:c5:ae:f2:06:a7:26:e4:41:5c:0e root@zabbix.example.com
The key's randomart image is:
+--[ DSA 1024]----+
| |
| E . |
| . + . |
| .o . o|
| S. o |
| . o . + .|
| oo.. B . |
| o +o * + |
| o .+ =. |
+-----------------+
----------------------
2.查看產生的秘鑰對:(ssh client)
# ls -lda .ssh
-----------------
drwx------ 2 root root 4096 6月 6 23:03 .ssh
-----------------
# cd .ssh
# ls -la
------------------
總用量 16
drwx------ 2 root root 4096 6月 6 23:03 .
dr-xr-x---. 26 root root 4096 6月 6 23:03 ..
-rw------- 1 root root 668 6月 6 23:03 id_dsa
-rw-r--r-- 1 root root 613 6月 6 23:03 id_dsa.pub
------------------
秘鑰產生完畢