ssh实现基于密钥方式登录系统
生活随笔
收集整理的這篇文章主要介紹了
ssh实现基于密钥方式登录系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
首先實現基于密鑰方式登錄系統的原理:
案例:實現密鑰方式登錄系統
規劃:
server:10.220.5.113
client:10.220.5.112
第一步:在客戶端器端創建一個密鑰對
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): #詢問1:密鑰對的保存位置 Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): #詢問2:對密鑰對加密密碼 Enter same passphrase again: #詢問3:確認密碼 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: 7d:e7:f4:ef:63:0b:26:fc:90:04:fd:d5:b6:e2:51:a4 root@BIGboss The key's randomart image is: +--[ RSA 2048]----+ | . | | . o .| | . . E oo| | .. . o..| | S ...+o. | | o.o+o. | | = +. .| | = .o.| | ..o=| +-----------------+ # 三次詢問均保持默認,按enter即可; # ls ~/.ssh/ <<<查看生成的密鑰對 id_rsa id_rsa.pub第二步:傳送公鑰到服務器端主機
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.220.5.113 The authenticity of host '10.220.5.113 (10.220.5.113)' can't be established. RSA key fingerprint is 5c:ae:6f:5e:a7:2f:bf:cb:27:fc:c9:a1:46:27:78:d1. Are you sure you want to continue connecting (yes/no)? yes(此處詢問是否確定繼續連接,輸入yes確認) Warning: Permanently added '10.220.5.113' (RSA) to the list of known hosts. root@10.220.5.113's password: (輸入客戶端對應用戶的登錄密碼) Now try logging into the machine, with "ssh 'root@10.220.5.113'", and check in:.ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.說明:
第三步:在10.220.5.113主機上確認公鑰文件是否傳輸到位:
[root@BIGboss ~]# ls -l /root/.ssh/ total 4 -rw------- 1 root root 394 Oct 21 01:39 authorized_keys測試:在客戶端可以直接登錄服務器端
# ssh 10.220.5.113 #ip addr show <<<查看是否已經登錄113主機------做運維之前很矯情的小年輕-----
總結
以上是生活随笔為你收集整理的ssh实现基于密钥方式登录系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssh服务基础
- 下一篇: windows(xshell)免密码登录