[转]CentOS下配置SSH密钥远程登陆

 

大致步骤:在服务器端生成一对密钥,然后公钥保存在服务器用户目录.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@tingso ~]$ ssh-keygen -b 1024 -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 smallfish@tingso.com

3).shell$ chmmod o+x /home/smallfish

[smallfish@tingso .ssh]$ 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即可。

 

转载于:https://www.cnblogs.com/efon/articles/2260738.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值