linux ssh免密码访问

56 篇文章 0 订阅

有一个master机器经常向slave机器发送文件和执行命令,免密码配置可以省去输入密码的麻烦。

 

 
master配置
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys
ssh localhost # 测试是否可以免密码访问本机

#ssh客户端免yes/no输入
vi /etc/ssh/ssh_config
> StrictHostKeyChecking no

 

 

slave配置
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

 

master分发公钥
scp ~/.ssh/id_rsa.pub root@119.188.7.66:~/.ssh/id_rsa.pub

 

 

slave授权
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys

 

=============

错误诊断:

Q:配置都OK的,但master访问slave还是需要密码

A:这个通常是目录权限的问题,如/root/.ssh权限要求是700,/root权限也要是700,诊断方法:slave机器执行:tail  /var/log/secure -f,然后mster执行连接命令,会有如下提示:

 

Sep 3 16:34:30 localhost sshd[17960]: Authentication refused: bad ownership or modes for directory /root/.ssh
Sep 3 16:34:30 localhost sshd[17960]: Authentication refused: bad ownership or modes for directory /root/.ssh
Sep 3 16:34:48 localhost sshd[17961]: Connection closed by 172.16.11.189
Sep 3 16:34:49 localhost sshd[17963]: Authentication refused: bad ownership or modes for directory /root
Sep 3 16:34:49 localhost sshd[17963]: Authentication refused: bad ownership or modes for directory /root

可见: /root/.ssh 和/root两个目录权限有问题,改为700就OK了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值