无法使用非 root 用户在我的 ubuntu 服务器上进行 SSH

无法使用非 root 用户在我的 ubuntu 服务器上进行 SSH

当我尝试以非 root 用户身份通过​​ SSH 连接到我的 Ubuntu 服务器时,连接始终无法正常工作,并且会话始终无法建立。但是从其他计算机连接却可以正常进行,所以这一定是我的 Mac 的问题。我不知道该怎么办。有什么建议吗?

▶ ssh [email protected] -vvv
OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname XXX.XXX.XXX.XXX is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/thefe/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/thefe/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to XXX.XXX.XXX.XXX [XXX.XXX.XXX.XXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48

并且没有打印任何输出...我被卡住了!

从 root 权限

▶ ssh [email protected] -vvv
OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname XXX.XXX.XXX.XXX is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/thefe/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/thefe/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to XXX.XXX.XXX.XXX [XXX.XXX.XXX.XXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
debug1: identity file /Users/thefe/.ssh/id_rsa type -1
debug1: identity file /Users/thefe/.ssh/id_rsa-cert type -1
debug1: identity file /Users/thefe/.ssh/id_ecdsa type -1
debug1: identity file /Users/thefe/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/thefe/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/thefe/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/thefe/.ssh/id_ed25519 type 3
debug1: identity file /Users/thefe/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/thefe/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/thefe/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/thefe/.ssh/id_xmss type -1
debug1: identity file /Users/thefe/.ssh/id_xmss-cert type -1
debug1: identity file /Users/thefe/.ssh/id_dsa type -1
debug1: identity file /Users/thefe/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.1 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to XXX.XXX.XXX.XXX:22 as 'root'
debug3: record_hostkey: found key type ED25519 in file /Users/thefe/.ssh/known_hosts:1
debug3: record_hostkey: found key type RSA in file /Users/thefe/.ssh/known_hosts:2
debug3: record_hostkey: found key type ECDSA in file /Users/thefe/.ssh/known_hosts:3
debug3: load_hostkeys_file: loaded 3 keys from XXX.XXX.XXX.XXX
debug1: load_hostkeys: fopen /Users/thefe/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug3: order_hostkeyalgs: have matching best-preference key type [email protected], using HostkeyAlgorithms verbatim
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: [email protected],curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,[email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: [email protected]
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
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:K+u2j5erBu0FjLlnky42rz1OcWocEvKvZWTYSYAojZY
debug3: record_hostkey: found key type ED25519 in file /Users/thefe/.ssh/known_hosts:1
debug3: record_hostkey: found key type RSA in file /Users/thefe/.ssh/known_hosts:2
debug3: record_hostkey: found key type ECDSA in file /Users/thefe/.ssh/known_hosts:3
debug3: load_hostkeys_file: loaded 3 keys from XXX.XXX.XXX.XXX
debug1: load_hostkeys: fopen /Users/thefe/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'XXX.XXX.XXX.XXX' is known and matches the ED25519 host key.
debug1: Found key in /Users/thefe/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: ssh_set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: ssh_set_newkeys: mode 0
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: /Users/thefe/.ssh/id_rsa
debug1: Will attempt key: /Users/thefe/.ssh/id_ecdsa
debug1: Will attempt key: /Users/thefe/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/thefe/.ssh/id_ed25519 ED25519 SHA256:jk0NUsRYmx1AZn7IuQLETN2emKSAkBhDao4xBvbAs3g
debug1: Will attempt key: /Users/thefe/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/thefe/.ssh/id_xmss
debug1: Will attempt key: /Users/thefe/.ssh/id_dsa
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
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: kex_input_ext_info: [email protected]=<0>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred 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: /Users/thefe/.ssh/id_rsa
debug3: no such identity: /Users/thefe/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /Users/thefe/.ssh/id_ecdsa
debug3: no such identity: /Users/thefe/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/thefe/.ssh/id_ecdsa_sk
debug3: no such identity: /Users/thefe/.ssh/id_ecdsa_sk: No such file or directory
debug1: Offering public key: /Users/thefe/.ssh/id_ed25519 ED25519 SHA256:jk0NUsRYmx1AZn7IuQLETN2emKSAkBhDao4xBvbAs3g
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /Users/thefe/.ssh/id_ed25519 ED25519 SHA256:jk0NUsRYmx1AZn7IuQLETN2emKSAkBhDao4xBvbAs3g
debug3: sign_and_send_pubkey: using [email protected] with ED25519 SHA256:jk0NUsRYmx1AZn7IuQLETN2emKSAkBhDao4xBvbAs3g
debug3: sign_and_send_pubkey: signing using ssh-ed25519 SHA256:jk0NUsRYmx1AZn7IuQLETN2emKSAkBhDao4xBvbAs3g
debug3: send packet: type 50
debug3: receive packet: type 52
Authenticated to XXX.XXX.XXX.XXX ([XXX.XXX.XXX.XXX]:22) using "publickey".
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: filesystem
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: client_input_hostkeys: received RSA key SHA256:G/fUdfsvO8DDVKP/egzqmb0Z6FBQd/QpXB/zCLR2DDY
debug3: client_input_hostkeys: received ECDSA key SHA256:U6x4RPdmzrxXVqS7rdDZNNvtcHgMlH+MCO3xVDcLg+0
debug3: client_input_hostkeys: received ED25519 key SHA256:K+u2j5erBu0FjLlnky42rz1OcWocEvKvZWTYSYAojZY
debug1: client_input_hostkeys: searching /Users/thefe/.ssh/known_hosts for XXX.XXX.XXX.XXX / (none)
debug3: hostkeys_foreach: reading file "/Users/thefe/.ssh/known_hosts"
debug3: hostkeys_find: found ssh-ed25519 key at /Users/thefe/.ssh/known_hosts:1
debug3: hostkeys_find: found ssh-rsa key at /Users/thefe/.ssh/known_hosts:2
debug3: hostkeys_find: found ecdsa-sha2-nistp256 key at /Users/thefe/.ssh/known_hosts:3
debug1: client_input_hostkeys: searching /Users/thefe/.ssh/known_hosts2 for XXX.XXX.XXX.XXX / (none)
debug1: client_input_hostkeys: hostkeys file /Users/thefe/.ssh/known_hosts2 does not exist
debug3: client_input_hostkeys: 3 server keys: 0 new, 3 retained, 0 incomplete match. 0 to remove
debug1: client_input_hostkeys: no new or deprecated keys from server
debug3: receive packet: type 4
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug3: receive packet: type 4
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug1: Sending environment.
debug3: Ignored env TERM_SESSION_ID
debug3: Ignored env SSH_AUTH_SOCK
debug1: channel 0: setting env LC_TERMINAL_VERSION = "3.4.19"
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env COLORFGBG
debug3: Ignored env ITERM_PROFILE
debug3: Ignored env XPC_FLAGS
debug1: channel 0: setting env LANG = "en_US.UTF-8"
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env PWD
debug3: Ignored env SHELL
debug3: Ignored env __CFBundleIdentifier
debug3: Ignored env TERM_PROGRAM_VERSION
debug3: Ignored env TERM_PROGRAM
debug3: Ignored env PATH
debug1: channel 0: setting env LC_TERMINAL = "iTerm2"
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env COLORTERM
debug3: Ignored env COMMAND_MODE
debug3: Ignored env TERM
debug3: Ignored env HOME
debug3: Ignored env TMPDIR
debug3: Ignored env USER
debug3: Ignored env XPC_SERVICE_NAME
debug3: Ignored env LOGNAME
debug3: Ignored env ITERM_SESSION_ID
debug3: Ignored env __CF_USER_TEXT_ENCODING
debug3: Ignored env SHLVL
debug3: Ignored env OLDPWD
debug3: Ignored env HOMEBREW_PREFIX
debug3: Ignored env HOMEBREW_CELLAR
debug3: Ignored env HOMEBREW_REPOSITORY
debug3: Ignored env MANPATH
debug3: Ignored env INFOPATH
debug3: Ignored env JAVA_HOME
debug3: Ignored env CLOUDSDK_PYTHON
debug3: Ignored env ANDROID_SDK
debug3: Ignored env FLUTTER_ROOT
debug3: Ignored env REACT_EDITOR
debug3: Ignored env NVM_DIR
debug3: Ignored env NVM_CD_FLAGS
debug3: Ignored env NVM_BIN
debug3: Ignored env NVM_INC
debug3: Ignored env ZSH
debug3: Ignored env PAGER
debug3: Ignored env LESS
debug3: Ignored env LSCOLORS
debug3: Ignored env LS_COLORS
debug3: Ignored env GREP_COLOR
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-generic x86_64)

<Session is now active and working>

编辑:

这是ll来自/root/.ssh

▶ ll
total 16K
-rw------- 1 root root  112 May  9 09:55 authorized_keys
-rw------- 1 root root 3.4K May  6  2020 id_rsa
-rw-r--r-- 1 root root  741 May  6  2020 id_rsa.pub
-rw-r--r-- 1 root root  840 Aug 29  2022 known_hosts

/home/thefe/.ssh是一个空文件夹

答案1

由于您域的域名系统 (DNS) 的配置,它可能适用于您的自定义域my-domain.com。服务器上的 SSH 配置最初允许直接 root 登录,但非 root 用户的配置可能设置为需要额外的步骤或额外的身份验证。此配置通常是出于安全原因,以强制使用域名并防止通过 IP 地址直接访问。

通过强制执行基于 DNS 名称的身份验证,服务器可以确保用户连接到目标域,并且不会绕过针对特定域名设置的任何潜在安全措施或访问限制。

编辑:用户评论说使用 DNS 名称代替 IP 地址可以解决问题。

答案2

看来服务器已分配给我的自定义域(我们称之为my-domain.com)。因此,如果我输入,而不是输入,它就可以完美地工作。root 用户可以使用 ip 地址或域名。我真的不知道为什么,但现在它可以工作了!ssh [email protected]ssh [email protected]

相关内容