基于Xshell使用密鑰方式連接遠(yuǎn)程主機(jī)
基于Xshell使用密鑰方式連接遠(yuǎn)程主機(jī),具體內(nèi)容如下
連接遠(yuǎn)程主機(jī),就驗(yàn)證身份而言,一般有兩種方式,一種是通過(guò)用戶(hù)密碼;另一種通過(guò)公鑰的方式(Public Key)。
圖1、xshell支持驗(yàn)證登錄用戶(hù)的方式
下面就使用Public Key的方式來(lái)實(shí)現(xiàn)連接,通過(guò)工具ssh-kengen生成密鑰對(duì)。
注意:操作之前需要ping通本機(jī)和目的主機(jī)(如果ping不通,可能的原因是防火墻、SELinux沒(méi)關(guān)閉,或者網(wǎng)關(guān)設(shè)置有問(wèn)題等)
使用XShell,這里使用的是XShell manager 5,目的主機(jī)為CentOS6,將需要連接的遠(yuǎn)程主機(jī)稱(chēng)為目的主機(jī)。
目的主機(jī)安裝ssh服務(wù)端,并開(kāi)啟
[root@node1 ~]$ yum install -y openssh-server # 安裝openssh服務(wù)端 [root@node1 ~]$ yum install -y openssh-clients #安裝openssh客戶(hù)端,可以不安裝 [root@node1 ~]$ service sshd start # 臨時(shí)開(kāi)啟sshd服務(wù) [root@node1 ~]$ chkconfig sshd on # 永久開(kāi)啟sshd服務(wù),服務(wù)器重啟也生效 [root@node1 ~]$service sshd status # 查看sshd服務(wù)運(yùn)行狀態(tài) openssh-daemon (pid 1384) 正在運(yùn)行... # 顯示正在運(yùn)行
生成ssh密鑰對(duì)(包括私鑰和公鑰)
[root@node1 ~]$ (umask 0077; ssh-keygen) # 生成ssh密鑰對(duì),并將權(quán)限設(shè)置為600 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): # 回車(chē) 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: fd:72:10:50:a6:7d:83:c7:93:d2:26:3d:12:0e:38:2f root@node1 The key's randomart image is: +--[ RSA 2048]----+ | .o.+ | | o B * . | | o. O % | | E .. O + | | .S o | | o | | . o | | o | | | +-----------------+ [root@node1 ~]$ cd .ssh/ [root@node1 .ssh]$ ll # 查看密鑰/公鑰對(duì)信息,權(quán)限都為600 總用量 8 -rw-------. 1 root root 1675 5月 21 14:26 id_rsa # 私鑰 -rw-------. 1 root root 392 5月 21 14:26 id_rsa.pub # 公鑰 [root@node1 .ssh]$
修改sshd連接配置文件vim /etc/ssh/sshd_config
PasswordAuthentication no # 不允許密碼驗(yàn)證登錄 PubkeyAuthentication yes # 允許公鑰驗(yàn)證登錄 AuthorizedKeysFile .ssh/id_rsa.pub # 指定公鑰文件路徑
將ssh密鑰對(duì)導(dǎo)出到本機(jī),建議創(chuàng)建一個(gè)目錄專(zhuān)用放置密鑰對(duì)
#]sz id_rsa #]sz id_rsa.pub
重載sshd服務(wù)
[root@node1 .ssh]$ service sshd reload 重新載入 sshd: [確定]
使用XShell連接
ssh root@IP
圖2、選擇密鑰文件
圖3、導(dǎo)入私鑰并確定
注意:點(diǎn)擊確定之后還要重新連接一次
圖4、連接成功
客戶(hù)端使用私鑰去驗(yàn)證,而遠(yuǎn)程主機(jī)使用公鑰驗(yàn)證。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。