服务器的操作系统:CentOS 6.6
我想为非root用户进行无密码登录,名为otheruser。 我在下面处理的步骤:
予。在服务器中生成公钥和私钥:
[otheruser@localhost ~]# ssh-keygen -t rsa
我接受默认设置,然后将.ssh/id_rsa.pub
重命名为authorized_keys
[otheruser@localhost ~/.ssh]# cp id_rsa.pub authorized_keys
[otheruser@localhost ~/.ssh]# ls -al ~
drwx------ 2 otheruser otheruser 4096 May 13 06:50 .ssh
[otheruser@localhost ~/.ssh]# ls -al ~/.ssh
drwx------ 2 otheruser otheruser 4096 May 13 06:50 .
drwxrwxr--. 4 otheruser otheruser 4096 May 9 07:23 ..
-rw------- 1 otheruser otheruser 412 May 13 06:50 authorized_keys
-rw------- 1 otheruser otheruser 1675 May 13 06:48 id_rsa
-rw------- 1 otheruser otheruser 412 May 13 06:48 id_rsa.pub
它可以注意到/home/otheruser/.ssh
的权限为700,而/home/otheruser/.ssh/authorized_keys
的权限为600,均属于uesr otheruser
和群组otheruser
。
II。修改/ etc / ssh / sshd_config
添加配置:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
AllowUsers otheruser
重新启动sshd服务:
[root@localhost ~]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
我将私钥从服务器复制到我的本地计算机。尝试ssh到服务器:
ssh -i id_rsa otheruse@192.168.1.101
但我收到了Permission denied
提示:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
/var/log/secure
中的记录是:
May 12 07:07:08 localhost sshd[1230]: Connection closed by 192.168.1.1
May 12 07:07:14 localhost sshd[1231]: Authentication refused: bad ownership or modes for directory /home/otheruser
我不知道我有什么问题。请有人帮助我QAQ
答案 0 :(得分:0)
哦,我通过引用此链接https://stackoverflow.com/a/35385148/8005570
来解决我的问题我所做的是更改/home/otheruser
[root@localhost ~] chmod go-w otheruser
但我仍然不明白造成这个问题的原因。