sshd错误显示authorized_keys路径中有双斜杠。

huangapple go评论53阅读模式
英文:

sshd error shows double slash in authorized_keys path

问题

当我添加另一个用户 bob 后,尝试连接时,客户端显示:

bob@1.2.3.4: Permission denied (publickey).

而服务器的日志显示:

sshd: Could not open user 'bob' authorized keys '/home/bob//.ssh/authorized_keys': Permission denied

那个双斜杠可能是问题所在。它是从哪里来的?

英文:

My server has an ssh user that works (so sshd works).

When I added another user bob, then tried to connect, the client shows:

bob@1.2.3.4: Permission denied (publickey).

And the server's logs show:

sshd: Could not open user 'bob' authorized keys '/home/bob//.ssh/authorized_keys': Permission denied

That double slash is probably the issue. Where is that coming from?

答案1

得分: 1

$ cat /etc/passwd | grep bob:

bob:.......:/home/bob/:/bin/bash

所以我执行了:

sudo usermod --home /home/bob bob

$ cat /etc/passwd | grep bob

bob:.......:/home/bob:/bin/bash

注意:
Linux忽略路径中的双斜杠,所以虽然这个操作在服务器上“修复”了日志错误,但根本问题仍然存在。要解决这个问题,请参考接受的答案。

英文:

$ cat /etc/passwd | grep bob:

bob:.......:/home/bob/:/bin/bash

So I did:

sudo usermod --home /home/bob bob

$ cat /etc/passwd | grep bob:

bob:.......:/home/bob:/bin/bash

NOTE:
Linux ignores double slashes in paths, so although this "fixed" the log error on the server, the underlying issue remained. To fix that, see the accepted answer.

答案2

得分: 1

我理解的情况是与authorized_keys文件的路径有关!通常与.ssh目录的权限或用户的主目录有关。

.ssh目录的权限应该为700,而authorized_keys文件的权限应该为600

所以首先检查它们:

ls -ld /home/bob/
ls -ld /home/bob/.ssh/
ls -l /home/bob/.ssh/authorized_keys

要修复这个问题,你可以这样做:

chmod 700 /home/bob/.ssh
chmod 600 /home/bob/.ssh/authorized_keys

如果权限设置正确,重新启动ssh服务并再次测试:

sudo systemctl restart sshd

还要检查authorized_keys必须位于以下路径:

/home/bob/.ssh/authorized_keys

祝你好运!

英文:

As I understand it shows that there is an issue with the path to the authorized_keys file!
usually it's related to the permissions of .ssh directory or the user's home directory.

the .ssh directory should have permissions of 700 and the authorized_keys file should have permissions of 600

so check them first :

ls -ld /home/bob/
ls -ld /home/bob/.ssh/
ls -l /home/bob/.ssh/authorized_keys

to fix that you can easily do like this :

chmod 700 /home/bob/.ssh
chmod 600 /home/bob/.ssh/authorized_keys

if the permissions are correct,restart ssh service and test it again

sudo systemctl restart sshd

also check the authorized_keys must be in this path :

/home/bob/.ssh/authorized_keys

good luck !

huangapple
  • 本文由 发表于 2023年6月22日 08:39:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527967.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定