linux普通用户生成密钥,CentOS下非root用户ssh key设置请教

服务器操作系统:CentOS 6.6

想为非root用户建立ssh免密码登录,假设该用户名为otheruser。

我执行的步骤为:

1. 在服务器上生成公钥和密钥

[otheruser@localhost ~]# ssh-keygen -t rsa

所有提示均采用默认选项。将生成的.ssh/id_rsa.pub改名字为authorized_keys,查看.ssh和authorized_keys的权限

[otheruser@localhost ~/.ssh]# cpid_rsa.pub authorized_keys

[otheruser@localhost~/.ssh]# ls -al ~drwx------ 2 otheruser otheruser 4096 May 13 06:50 .ssh[otheruser@localhost~/.ssh]# ls -al ~/.sshdrwx------ 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:50authorized_keys-rw------- 1 otheruser otheruser 1675 May 13 06:48id_rsa-rw------- 1 otheruser otheruser 412 May 13 06:48 id_rsa.pub

可以看出~/.ssh的权限是700,~/.ssh/authorized_keys的权限是600,用户和组均为otheruser。

然后将私钥通过scp拷贝到本地机上。

2. 修改/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 (publickey,gssapi-keyex,gssapi-with-mic,password).

在服务器上查看/var/log/secure,有以下记录

May 12 07:07:08 localhost sshd[1230]: Connection closed by 192.168.1.1May12 07:07:14 localhost sshd[1231]: Authentication refused: bad ownership or modes for directory /home/otheruser

提示说拥有权限或者模式不对。但是我目前没有想到问题出在哪里,想请教各位有没有解决的方法。感谢啊

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值