除非用户在 /etc/passwd 和 /etc/shadow 上有条目,否则服务器不会允许 ssh 连接

除非用户在 /etc/passwd 和 /etc/shadow 上有条目,否则服务器不会允许 ssh 连接

我最近接管了几台服务器的管理。两台服务器都需要允许jenkins用户通过 ssh 连接,这些用户由 LDAP 管理。当我输入 时,两台服务器都会显示用户信息id jenkins

我在两台服务器中为用户创建了一个home目录。两台服务器在用户文件中都包含相同的公钥authorized_keys。所有权限设置都相同。

当尝试server A以用户身份通过​​ ssh 进入时jenkins,日志会显示以下内容。

debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /jenkins/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA KEY
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /jenkins/.ssh/id_dsa
debug3: no such identity: /jenkins/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /jenkins/.ssh/id_ecdsa
debug3: no such identity: /jenkins/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /jenkins/.ssh/id_ed25519
debug3: no such identity: /jenkins/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

Server B当以同一台服务器的用户身份ssh 进入时jenkins,日志显示的内容如下。

debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /jenkins/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA KEY
debug2: we sent a publickey packet, wait for reply
debug1: Authentication succeeded (publickey).
Authenticated to SERVER A ([IP ADDRESS]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
debug3: Ignored env SHELL
debug3: Ignored env TERM
debug3: Ignored env USER
debug3: Ignored env SUDO_USER
debug3: Ignored env SUDO_UID
debug3: Ignored env USERNAME
debug3: Ignored env MAIL
debug3: Ignored env PATH
debug3: Ignored env PWD
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: Ignored env SHLVL
debug3: Ignored env SUDO_COMMAND
debug3: Ignored env HOME
debug3: Ignored env LOGNAME
debug3: Ignored env SUDO_GID
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0

基本上,jenkins用户可以通过 ssh 进入Server A,但当Server B两台服务器都包含相同的用户主目录时则不行。我不得不修改/etc/passwd/etc/shadow文件Server A才能使其正常工作。

这里发生了什么?

答案1

getent passwd jenkins按照 David 的建议运行,结果显示两台机器上用户的主目录路径设置不同。这解决了我的问题。

相关内容