ssh配置authorized_keys后仍然需要…

更多 0

前阵子搭建Hadoop时,配置了本机(localhost)的ssh的公钥到authorized_keys文件中,但是在ssh连接 localhost时仍然提示需要输入密码,后来发现是$HOME/.ssh/authorized_keys这个文件的权限问题引起的。其原因是,不能 让所有者之外的用户对authorized_keys文件有写权限,否则,sshd将不允许使用该文件,因为它可能会被其他用户篡改。
命令行的演示如下:

View Code BASH

[hadoop@guest1 ~]$ cd .ssh/

[hadoop@guest1 .ssh]$ ll
total 16
-rw-rw-r-- 1 hadoop hadoop 395 Jan 12 18:37 authorized_keys
-rw------- 1 hadoop hadoop 1675 Jan 12 18:36 id_rsa
-rw-r--r-- 1 hadoop hadoop 395 Jan 12 18:36 id_rsa.pub
 -rw-r--r-- 1 hadoop hadoop 796 Jan 6 08:40 known_hosts
#注意这里的authorized_keys文件的权限;这时该文件中的key是不起作用的。 
 #用chmod修改authorized_keys文件的权限
 [hadoop@guest1 .ssh]$ chmod g-w authorized_keys
 [hadoop@guest1 .ssh]$ ll
total 16
 -rw-r--r-- 1 hadoop hadoop 395 Jan 12 18:37 authorized_keys
 -rw------- 1 hadoop hadoop 1675 Jan 12 18:36 id_rsa
 -rw-r--r-- 1 hadoop hadoop 395 Jan 12 18:36 id_rsa.pub
-rw-r--r-- 1 hadoop hadoop 796 Jan 6 08:40 known_hosts
  #修改后,sshd就可以正常使用authorized_keys文件了


如果authorized_keys文件、$HOME/.ssh目录 或 $HOME目录让本用户之外的用户有写权限,那么sshd都会拒绝使用 ~/.ssh/authorized_keys 文件中的key来进行认证的。
“man sshd”命令查看对authorized_keys文件的描述如下:

man sshd .....
~/.ssh/authorized_keys Lists the public keys (DSA/ECDSA/RSA) that can be used for logging in as this user. The format of this file is described above. The content of the file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others.   If this file, the ~/.ssh directory, or the user's home directory are writable by other users, then the file could be modified or replaced by unauthorized users. In this case, sshd will not allow it to be used unless the StrictModes option has been set to “no”.
 ........
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值