遠(yuǎn)程攻略:SecureCRT使用RSA密鑰登陸SSH
一直在SecureCRT上使用密碼和鍵盤(pán)交互方式登陸ssh,一直沒(méi)試成功,今天無(wú)意在一篇文章里受了點(diǎn)啟發(fā),順便就在前些天裝的虛擬機(jī)上試成了??蛻?hù)端用的SecureCRT5.5.1,服務(wù)端為openSUSE10.3上默認(rèn)安裝的OpenSSH_4.6p1。
首先配置SecureCRT上的RSA密鑰,打開(kāi)SecureCRT→Quick Connect→Authentiation→PublicKey→Properties→Create Identity File,Key選擇RSA;Passphrase可以不同于密碼,任意的字符串即可;Key length in為加密長(zhǎng)度,可為512到2048位,要是在linux上可配置4096;下一步為生成過(guò)程,需要不停在進(jìn)度條附近晃動(dòng)鼠標(biāo),選擇在x:\%USERPROFILE%\Application Data\VanDyke下生成兩個(gè)文件,并且格式為Openssh Key format,要是選默認(rèn)的Standard Public Key and VanDyke Private Key可能還需要格式轉(zhuǎn)換或有兼容問(wèn)題,公鑰Identity.pub和私鑰Identity。
然后在opensuse上要使用密鑰方式登陸的的用戶(hù)目錄下建立.ssh目錄,這里我偷懶直接運(yùn)行ssh-keygen工具創(chuàng)建本機(jī)密鑰會(huì)自動(dòng)創(chuàng)建.ssh目錄并設(shè)置合適目錄權(quán)限。
lxuser@suse10:/etc/ssh> ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lxuser/.ssh/id_rsa):
Created directory '/home/lxuser/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/lxuser/.ssh/id_rsa.
Your public key has been saved in /home/lxuser/.ssh/id_rsa.pub.
The key fingerprint is:
d8:07:b9:d6:f9:4d:0c:e3:c7:8c:82:f4:a3:20:71:f4 lxuser@suse10
利用sftp或其他方式將公鑰Identity.pub上傳到剛建立好的.ssh目錄里,修改文件名為authorized_keys2,這是因?yàn)槭褂玫氖莂uthorized_keys這個(gè)文件,而用的ssh版本為2(openSUSE默認(rèn)也僅使用Protocol 2).
lxuser@suse10:~/.ssh> mv Identity.pub authorized_keys2
為安全起見(jiàn),修改該文件的訪問(wèn)權(quán)限,保證除屬主外沒(méi)人能修改
lxuser@suse10:~/.ssh> chmod 600 authorized_keys2
總計(jì) 16 -rw------- 1 lxuser users 234 11-02 20:20 authorized_keys2 -rw------- 1 lxuser users 1743 11-02 19:23 id_rsa -rw-r--r-- 1 lxuser users 395 11-02 19:23 id_rsa.pub 再回到SecureCRT,在Quick Connect→Authentiation處僅勾選PublicKey,并設(shè)置屬性Properties,指定Use identity or certificate file為私鑰Identity,確定后連接,正常的話會(huì)提示輸入前面設(shè)置的Passphrase,若成功則直接登陸了。 Last login: Fri Nov 2 20:38:21 2007 from printer.mshome.net Have a lot of fun... 至此任務(wù)算基本成功了。既然已經(jīng)成功使用了ssh的RSA功能,那么索性讓openssh只支持RSA驗(yàn)證,否則既支持普通密碼又支持RSA就沒(méi)什么意思了,根本沒(méi)把安全提高。 修改ssh_config配置文件 lxuser@suse10:/etc/ssh> vi ssh_config 取消密碼登陸驗(yàn)證 PasswordAuthentication no 然后重啟sshd服務(wù)再次嘗試用鍵盤(pán)和密碼交互登陸,就提示不成功了,而使用PublicKey是方便了許多,免去了反復(fù)輸入密碼的麻煩,安全較高(不過(guò)要是客戶(hù)端宿主機(jī)本身不安全,那后果也就......)。 suse10:/etc/ssh # vi ssh_config suse10:/etc/ssh # rcsshd restart Shutting down SSH daemon done Starting SSH daemon done