一直在SecureCRT上使用密碼和鍵盤交互方式登陸ssh,一直沒試成功,今天無意在一篇文章里受了點啟發(fā),順便就在前些天裝的虛擬機上試成了??蛻舳擞玫腟ecureCRT5.5.1,服務(wù)端為openSUSE10.3上默認安裝的OpenSSH_4.6p1。 首先配置SecureCRT上的RSA密鑰,打開SecureCRT→Quick Connect→Authentiation→PublicKey→Properties→Create Identity File,Key選擇RSA;Passphrase可以不同于密碼,任意的字符串即可;Key length in為加密長度,可為512到2048位,要是在linux上可配置4096;下一步為生成過程,需要不停在進度條附近晃動鼠標(biāo),選擇在x:\%USERPROFILE%Application DataVanDyke下生成兩個文件,并且格式為Openssh Key format,要是選默認的Standard Public Key and VanDyke Private Key可能還需要格式轉(zhuǎn)換或有兼容問題,公鑰Identity.pub和私鑰Identity。 然后在opensuse上要使用密鑰方式登陸的的用戶目錄下建立.ssh目錄,這里我偷懶直接運行ssh-keygen工具創(chuà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,這是因為使用的是authorized_keys這個文件,而用的ssh版本為2(openSUSE默認也僅使用Protocol 2). lxuser@suse10:~/.ssh> mv Identity.pub authorized_keys2 為安全起見,修改該文件的訪問權(quán)限,保證除屬主外沒人能修改 lxuser@suse10:~/.ssh> chmod 600 authorized_keys2 > 總計 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,確定后連接,正常的話會提示輸入前面設(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驗證,否則既支持普通密碼又支持RSA就沒什么意思了,根本沒把安全提高。 修改ssh_config配置文件 lxuser@suse10:/etc/ssh> vi ssh_config 取消密碼登陸驗證 PasswordAuthentication no 然后重啟sshd服務(wù)再次嘗試用鍵盤和密碼交互登陸,就提示不成功了,而使用PublicKey是方便了許多,免去了反復(fù)輸入密碼的麻煩,安全較高(不過要是客戶端宿主機本身不安全,那后果也就......)。 suse10:/etc/ssh # vi ssh_config suse10:/etc/ssh # rcsshd restart Shutting down SSH daemon done Starting SSH daemon done |
|