大家都介紹的是*nux機器ssh訪問*nux的時候可以用RSA證書認證代替密碼(當然這必須要求被登錄的sshd服務器啟用允許證書認證,因為 我有時候不允許這個),其實windows訪問sshd的時候也可以,當然你必須安裝ssh或者cygwin。下面我以cygwin為例:
首先在cygwin下執(zhí)行ssh-keygen -d
[vitter@securitycn ~]# ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/home/vitter/.ssh/id_dsa): (采用缺省值,回車)
Created directory '/home/vitter/.ssh'.
Enter passphrase (empty for no passphrase): (不用密碼,回車)
Enter same passphrase again: (回車)
Your identification has been saved in /home/vitter/.ssh/id_dsa.
Your public key has been saved in /home/vitter/.ssh/id_dsa.pub.
The key fingerprint is:
71:50:79:88:70:86:98:c3:b9:48:40:17:2d:21:e8:de vitter@securitycn
這樣,在/home/vitter/.ssh目錄下生成如下兩個文件:
id_dsa
id_dsa.pub
將id_dsa.pub傳到sshd服務器上。
然后把里面的內(nèi)容添加到服務器要登錄的用戶的.ssh目錄下的authorized_keys文件中(以root為例):
[root@sshd1 ~]# cat id_dsa.pub >> /root/.ssh/authorized_keys
這樣在windows下以后直接 ssh root@sshd1 就可以不用密碼了。
[vitter@securitycn ~]# ssh root@sshd1
沒有密碼輸入提示了。
如果用SecureCrt可以直接把生成密鑰導入?;蛘哂肧ecureCrt也可以生成密鑰:
關于SecureCrt使用ssh2的補充
很多朋友都來問我ssh2如何實現(xiàn).的確用ssh1有點過時了,不妨補充一下ssh2的使用說明,其實看了ssh1的使用說明,再來用ssh2一樣很簡單.
1.首先產(chǎn)生ssh2的秘匙對,我選擇使用RSA加密.
Generate your key in SecureCRT (Global Options ->SSH2 ->Create Identity File) in RSA format
用SecureCRT生成RSA格式的密鑰對,操作步驟:選項 -> 全局選項 -> SSH2 -> 創(chuàng)建身份文件
2.在linux服務器上建立.ssh目錄,如果你以前已經(jīng)在正常使用ssh1了,那就這一步可以不做,比如我這里要用root帳戶使用ssh2
mkdir /root/.ssh
chmod 700 /root/.ssh
3.把生成的 identity.pub 傳到linux服務器上,如果你已經(jīng)在用SecureCrt,可以參考《SecureCRT來上傳和下載數(shù)據(jù)》http://hi.baidu.com/dlzok/blog/item/1739fc1fde4800f8e1fe0b22.html
4.導入公匙
ssh-keygen -X -f Identity.pub >> /root/.ssh/authorized_keys
對于不是用openssh的,因為不同軟件生成的密鑰是不通用的,所以方法有點變化,比如用Secure Shell的:
1. 在本地主機(比如,local)上生成自己的ssh公鑰和私鑰。命令如下:
local# ssh-keygen
Generating 1024-bit dsa key pair
Key generated.
1024-bit dsa, teng@ns, Fri Oct 20 2000 17:27:05
Passphrase :************ /*在此輸入你的口令,以后訪問這臺主機時要用。
Again :************ /*
Private key saved to /home1/teng/.ssh2/id_dsa_1024_a
Public key saved to /home1/teng/.ssh2/id_dsa_1024_a.pub
生成的私鑰和公鑰(id_dsa_1024_a和id_dsa_1024_a.pub)存放在你目錄的~/.ssh2目錄下。和用戶相關的SSH配置文件 都在~/.ssh2下。私鑰由用戶保存在本地主機上,而公鑰需傳送到遠地主機的你自己的賬號的~/.ssh2下,如果你要用ssh2訪問本地主機的話。
2. 在~/.ssh2下創(chuàng)建“identification”文件用來說明進行身份認證的私鑰。命令如下:
local:~/.ssh2# echo "IdKey id_dsa_1024_a" > identification
3.同樣地,在遠地主機(比如,remote)上完成上面步驟。
4.將本地(local)下你自己(這里是“teng”)的公鑰(id_dsa_1024_a.pub)拷貝到遠地主機(remote.54ncr.com)上你自己家目錄下的.ssh2目錄下,可命名為“l(fā)ocal.pub”,一般用ftp上傳即可。
5. 在遠地主機上,你自己家目錄的.ssh2目錄下,創(chuàng)建“authorization”文件,其中指定用來進行身份認證的公鑰文件。命令如下:
remote:~/.ssh2# echo “Key local.pub” > authorization
6. 現(xiàn)在你可以從本地用ssh2登錄到遠地系統(tǒng)了。命令如下:
local# ssh remote
Passphrase for key "/home1/teng/.ssh2/id_dsa_1024_a" with comment "1024-bit dsa,
teng@ns, Fri Oct 20 2000 17:27:05":***********
這時會要你輸入你的ssh口令(Passphrase)。驗證通過后,即登錄到remote主機上。