基于xshell使用密鑰方式連接遠(yuǎn)程主機(jī),具體內(nèi)容如下
連接遠(yuǎn)程主機(jī),就驗(yàn)證身份而言,一般有兩種方式,一種是通過用戶密碼;另一種通過公鑰的方式(public key)。
圖1、xshell支持驗(yàn)證登錄用戶的方式
下面就使用public key的方式來實(shí)現(xiàn)連接,通過工具ssh-kengen生成密鑰對(duì)。
注意:操作之前需要ping通本機(jī)和目的主機(jī)(如果ping不通,可能的原因是防火墻、selinux沒關(guān)閉,或者網(wǎng)關(guān)設(shè)置有問題等)
使用xshell,這里使用的是xshell manager 5,目的主機(jī)為centos6,將需要連接的遠(yuǎn)程主機(jī)稱為目的主機(jī)。
目的主機(jī)安裝ssh服務(wù)端,并開啟
1
2
3
4
5
6
|
[root@node1 ~]$ yum install -y openssh-server # 安裝openssh服務(wù)端 [root@node1 ~]$ yum install -y openssh-clients #安裝openssh客戶端,可以不安裝 [root@node1 ~]$ service sshd start # 臨時(shí)開啟sshd服務(wù) [root@node1 ~]$ chkconfig sshd on # 永久開啟sshd服務(wù),服務(wù)器重啟也生效 [root@node1 ~]$service sshd status # 查看sshd服務(wù)運(yùn)行狀態(tài) openssh-daemon (pid 1384) 正在運(yùn)行... # 顯示正在運(yùn)行 |
生成ssh密鑰對(duì)(包括私鑰和公鑰)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[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 ): # 回車 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
1
2
3
|
passwordauthentication no # 不允許密碼驗(yàn)證登錄 pubkeyauthentication yes # 允許公鑰驗(yàn)證登錄 authorizedkeysfile . ssh /id_rsa .pub # 指定公鑰文件路徑 |
將ssh密鑰對(duì)導(dǎo)出到本機(jī),建議創(chuàng)建一個(gè)目錄專用放置密鑰對(duì)
1
2
|
#]sz id_rsa #]sz id_rsa.pub |
重載sshd服務(wù)
1
2
|
[root@node1 . ssh ]$ service sshd reload 重新載入 sshd: [確定] |
使用xshell連接
1
|
ssh root@ip |
圖2、選擇密鑰文件
圖3、導(dǎo)入私鑰并確定
注意:點(diǎn)擊確定之后還要重新連接一次
圖4、連接成功
客戶端使用私鑰去驗(yàn)證,而遠(yuǎn)程主機(jī)使用公鑰驗(yàn)證。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。