SSH 公钥不适用于特定用户

Sta*_*ale 2 ssh permissions key-authentication

我在一个系统上有 2 个用户,user1 和 user2。

这是每个的authorized_keys的md5sum:

de092f77fb4a3be2cd8864c5f9961149  user1/.ssh/authorized_keys
de092f77fb4a3be2cd8864c5f9961149  user2/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

以下是每个 .ssh 文件夹的列表:

user1/.ssh/:
total 8
drwx------. 2 user1 user1   28 Mar 16 12:11 .
drwxrwx---. 5 user1 user1 4096 Mar 16 12:11 ..
-rw-------. 1 user1 user1  412 Mar 16 12:11 authorized_keys

user2/.ssh/:
total 4
drwx------. 2 user2 user2  28 Mar 16 11:37 .
drwx------. 3 user2 user2  90 Mar 16 11:38 ..
-rw-------. 1 user2 user2 412 Mar 16 11:37 authorized_keys
Run Code Online (Sandbox Code Playgroud)

这是每个的身份验证:

用户 1:

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/me/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Run Code Online (Sandbox Code Playgroud)

用户 2:

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/me/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg ssh-rsa blen 279
Run Code Online (Sandbox Code Playgroud)

/etc/passwd:

user1:x:1001:1001::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
Run Code Online (Sandbox Code Playgroud)

换句话说,我可以使用 user2 使用公钥登录,但不能使用 user1。使用密码登录对两者都适用。我不知道为什么这适用于一个用户而不是另一个用户。而且我需要获得公钥身份验证才能与 user1 一起使用(因为我需要使用公钥身份验证使用 sshagent 运行脚本)

我不知道在哪里寻找为什么这不起作用。所有在线指南都要求检查密钥、权限并重新生成。但以上所有看起来都是正确的。我发现 /etc/ssh 文件夹中没有提到 user1。

如果我提供密码,登录就可以正常工作。

请注意,我已编辑用户名以使相关数据匿名。

Sta*_*ale 6

问题是主文件夹的权限,它允许组写入。