Centos 5.4下使用ssh key 遠程登陸

2010-3-8 12:41
大致步驟:在服務器端生成一對密鑰,然後公鑰保存在服務器用戶目錄.ssh下的authorized_keys2,是個隱藏的目錄。私鑰必須將id_dsa下載到客戶端,然後通過puttygen.exe生成.ppk文件。當用戶登錄時,服務器會根據公鑰來比較私鑰,如果相符就允許登陸,否則拒絕。私鑰只保存在客戶端中,及時有人知道root密碼,沒有私鑰也不能遠程登錄到服務器上。
 

Centos 5.4 ssh key 配置:
1. Server:
1).shell# vi /etc/ssh/sshd_config 修改以下配置:
Port 20000
Protocol 2
PasswordAuthentication no
2).#爲了安全起見,ssh key方式用普通用戶登錄,例如smallfish
[smallfish@host ~]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/smallfish/.ssh/id_dsa):
Created directory '/home/smallfish/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/smallfish/.ssh/id_dsa.
Your public key has been saved in /home/smallfish/.ssh/id_dsa.pub.
The key fingerprint is:
68:e2:be:31:5a:d0:3c:0f:6d:48:31:69:13:9c:58:f3 [email protected]
3).shell$ chmmod o+x /home/smallfish
[[email protected]]$ ls
id_dsa  id_dsa.pub
4).mv id_dsa.pub authorized_keys2
5).download id_dsa to windows   #一般爲了方便下載到putty目錄下,用於生成ppk文件
6).shell# service sshd restart
2. Client:
#生成ppk文件
1).open puttygen.exe--Conversions--import key--id_dsa--Enter passpharase for key--Save private key--保存爲*.ppk(例如server.ppk)
#啓動客戶端測試
2).open putty.exe--Category-SSH-Auth-Private key file for authentication #導入ppk文件
#輸入之前在server上設定的passphrase登錄
3).login as: smallfish
Authenticating with public key "imported-openssh-key"
Passphrase for key "imported-openssh-key":

Ok, 配置完成。
問題:
1.客戶端用key登陸的時候提示:
Disconnected: No supported authentication methods available
 解決:是由於在客戶端puttygen生成ppk文件的時候重新用了Generate命令,直接導入id_dsa文件然後save private key即可。
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章