ssh免密码自动登录及相关问题解决

1 自动登录

A为客户端,B为服务器,目的是从A ssh远程登录到B不需输入密码

 

在A上:

#ssh-keygen -t dsa (连续三次回车, 使用缺省值)

#scp ~/.ssh/id_dsa.pub  [remoteuser]@[remotehost]:

在B上:

#cat  ~/.ssh/id_dsa.pub  >> ~/.ssh/authorized_keys

#chmod 644 ~/.ssh/authorized_keys

 

2 问题一: 每次执行ssh  [remoteuser]@[remotehost] 都要输入密码, 尽管按照1建立了ssh相互认证

解决办法:

A和B的HOME目录的权限必须为700

在A和B上都执行: #chmod -R 700 /home/[user]

 

在B上, ~/.ssh/authorized_keys权限为644

#chmod 644 ~/.ssh/authorized_keys

 

2 问题二:ssh或scp连接的时候很慢

解决办法:

最为常见的原因是B上的sshd会去DNS查找访问A IP的hostname, 如果DNS不可用或无相关记录, 则会导致很长的时延

1)在B上/etc/hosts文件中把A的ip和hostname加入

2)在B上/etc/ssh/sshd_config文件中修改或加入 UseDNS=no

3)注释掉/etc/resolv.conf中所有行

4)修改B 上/etc/nsswitch.conf中hosts为hosts:files

5)reboot B

 

另外也有可能涉及openssh kerberos authenticatioin。 如果执行 ssh -v remoteip, 显示如下:

debug1: Next authentication method: gssapi-with-mic

debug1: Unspecified GSS failure. Minor code may provide more information

No credentials cache found

则在B上/etc/ssh/sshd_config文件中修改

#GSAPI options

#GSSAPIAuthentication no

#GSSAPIAuthentication yes

#GSSAPICleanupCredentails yes

#GSSAPICleanupCredentails yes

然后重起sshd

/etc/init.d/sshd restart

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值