使用登录时安装的密钥和主文件夹进行 SSH 登录

使用登录时安装的密钥和主文件夹进行 SSH 登录

我必须连接到服务器,当用户登录时安装用户主文件夹,并在一段时间不活动后卸载。我不知道他们是怎么做到的,但ls /home我通过一个简单的方法发现了它。

我设置了一个密钥对,以避免每次 ssh 进入该服务器时都输入密码。
我检查了~/.ssh/authorized_keys服务器,密钥是正确的。
之后ssh-copy-id它就没有问题了,但第二天它问我密码。同一天,下一次登录可以使用密钥开箱即用。

所以我猜测有时密钥不起作用的原因是因为我的主文件夹(等~/.ssh/authorized_keys)尚未安装。

我已经尝试过,cat /etc/ssh/sshd_config但我什至没有阅读权限。

我无法猜测任何可能的解决方案。

第一次尝试:

❯ ssh -v <username>@<host>
OpenSSH_9.0p1, OpenSSL 1.1.1q  5 Jul 2022
debug1: Reading configuration data /home/dpd-/.ssh/config
debug1: /home/dpd-/.ssh/config line 18: Applying options for <host>
debug1: /home/dpd-/.ssh/config line 41: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 5: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/run/user/1000/kssh-316772-62ebc2b2eab867050f1276d08a9eed0a7d94401d" does not exist
debug1: Connecting to <host> [<ip>] port 22.
debug1: Connection established.
debug1: identity file /home/dpd-/.ssh/DEI type 3
debug1: identity file /home/dpd-/.ssh/DEI-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.7
debug1: compat_banner: match: OpenSSH_8.7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to <host>:22 as '<username>'
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:<hash>
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '<host>' is known and matches the ED25519 host key.
debug1: Found key in /home/dpd-/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /home/dpd-/.ssh/DEI ED25519 SHA256:<hash> explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/dpd-/.ssh/DEI ED25519 SHA256:<hash> explicit
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: password
<username>@<host>'s password: 

后来的尝试:

❯ ssh -v <username>@<host>
debug1: multiplexing control connection
debug1: channel 1: new [mux-control]
debug1: channel 1: free: mux-control, nchannels 2
OpenSSH_9.0p1, OpenSSL 1.1.1q  5 Jul 2022
debug1: Reading configuration data /home/dpd-/.ssh/config
debug1: /home/dpd-/.ssh/config line 18: Applying options for <host>
debug1: /home/dpd-/.ssh/config line 41: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 5: Applying options for *
debug1: auto-mux: Trying existing master
debug1: multiplexing control connection
debug1: channel 1: new [mux-control]
debug1: channel 2: new [client-session]
    if [ -z "$python" -o ython=$(command -v python))*" > /dev/stderr; cleanup_on_bootstrap_exit; exit 1; }4\\\\\\n\\\\\\041)"'  '/bin/sh
debug1: mux_client_request_session: master session id: 2
no-rc enabled
$

相关内容