`
mineral
  • 浏览: 287449 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

不输密码登录SSH

阅读更多


环境:

Debian Linux (sarge)
openSSH

步骤:

1.安装好ssh

#apt-get install ssh

2.配置openSSH为允许PubkeyAuthentication认证

编辑sshd_config配置文件

#vim /etc/ssh/sshd_config

找到#PubkeyAuthentication yes并把注释去掉
找到#AuthorizedKeysFile     ~/.ssh/authorized_keys,去掉注释

 

#找到useDNS yes

改为useDNS no

不改的话ssh客户端连接的时候会很慢。


这两行的意思是打开Pubkey认证方式,把pubkey放在~/.ssh/authorized_keys ,在我的机器上对应的是/root/.ssh/authorized_keys


3.生成登录用的key,就是登录时用到的公钥和私钥  在Client机器上

Linux用:
#ssh-keygen -t rsa

会有提示,直接按回车就行了;
在提示输入passwdphrase的时候,你可以输入一个密码,如果使用空密码也行,直接按回车即可。
这样,会在/root/.ssh/下生成两个文件   id_rsa  和id_rsa.pub   .pub是公钥文件

winows用:

 

SecureCRT软件里:

 

工具-》创建公钥,然后一步一步就行了。

 

 


4.把公钥加入到authorized_keys中,以让服务端认识你的公钥 ,(在服务器上执行)

把第3步生成的id_rsa.pub传到服务器上,比如放在/root/id_rsa.pub


#cd ~/.ssh
#cat /root/id_rsa.pub >> authorized_keys


5.重启sshd服务

#/etc/init.d/ssh restart


6.客户端使用测试连接性

以SecureCRT这个ssh的客户端为例,我是Windows XP.

在QuickConnect的连接对话框里,认证方式里勾选 PublicKey,并且往上挪到第一个,在Properties里选择刚才下载到id_dsa私钥文件,然后"OK",再点"Connect",是不是登录进去了,很方便吧。再也不用你输密码了。


7.其它选项

为了安全起见,如果你的主机只有你一两个人需要登录主机,可以禁用掉其它的Passord认证方式。方法是:sshd_config配置文件里。

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes    #======》这里把注释去掉,并改成no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes    #========>把注释去掉,并改成no



Reference:

 

http://www.linuxfly.org/post/175.htm

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics