ssh基於key認證登陸
一、在客戶端生成密鑰對
ssh-keygen -t rsa [-P ''] [-f “~/.ssh/id_rsa"]
## -r rsa:指定算法
## -P :加對稱祕鑰口令
## -f :可以指定生成路徑
## /.ssh/id_rsa 生成祕鑰默認路徑
我們簡單操作就不加密碼了
[root@centos7 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Y9ia1CPAxegHbp767h8I5iLKCpLxuHxZxB7gfWSIkLw root@centos7
The key's randomart image is:
+---[RSA 2048]----+
|..o .oo |
| o +oo.o |
| oo*.o |
| E .+*.= |
|. oooo* S |
| B .o= = o |
|B o.+ + |
|Bo.o . |
|=o.++.. |
+----[SHA256]-----+
查看生成的公鑰和私鑰
[root@centos7 .ssh]#ls
id_rsa id_rsa.pub
## id_rsa私鑰
## id_rsa.pub公鑰
二、把公鑰文件傳輸至遠程服務器
ssh-copy-id [-i [公鑰文件]] [user@]host
如果傳輸時寫時誤傳了私鑰文件系統會自動轉換成公鑰文件傳輸,不用緊張
三、測試
[root@centos5 .ssh]#ssh 192.168.27.6
Last login: Sun Jan 14 17:04:42 2018 from 192.168.27.1
[root@centos6 ~]#
登陸成功