1. 程式人生 > >怎樣部署ssh免密鑰登錄

怎樣部署ssh免密鑰登錄

生成 enter user exist file 0.10 zed 服務 host

SSH免密鑰登錄其實很簡單,只需幾步就能部署完成。
測試環境:CentOS Linux release 7.1.1503 (Core)
步驟如下:
1. 在主機上生成公鑰和密鑰!
[ Thegod:~ chengde$ ssh-keygen #一直回車即可!
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chengde/.ssh/id_rsa):
/Users/chengde/.ssh/id_rsa already exists.
...

2. 第一步執行完成後,會在你當前登錄的用戶的宿主目錄下生成一個.ssh的目錄,在.ssh目錄下會生成兩個文件(id_rsa和id_rsa.pub)私鑰和公鑰

Thegod:~ chengde$ cd .ssh/
Thegod:.ssh chengde$ ls
id_rsa id_rsa.pub known_hosts

3. 將公鑰(id_rsa.pub)移動到要免密碼登錄的服務器的用戶家目錄下的.ssh目錄下並改名為authorized_keys
Thegod:.ssh chengde$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Remarks: 如果需要免密鑰登錄的服務器的用戶家目錄下的.ssh目錄下已經有authorized_keys這個文件了,那麽就將公鑰追加到這個文件中,如果覆蓋了裏面的內容就更改了!(此內容只適合多臺服務器免密鑰登錄這臺服務器)

4.測試,完成

Thegod:.ssh chengde$ ssh [email protected]
Last failed login: Sun Jan 28 21:13:04 CST 2018 from 218.65.30.30 on ssh:notty
There were 883 failed login attempts since the last successful login.
Last login: Sun Jan 28 20:30:20 2018 from 139.215.216.12
[root@server59 ~]#

怎樣部署ssh免密鑰登錄