可以登录 sftp,但不能登录 ssh shell

可以登录 sftp,但不能登录 ssh shell

我试图为我的服务器 (Ubuntu 20.04) 设置一个新的 sftp 用户。我创建了用户my-user,将公钥添加到他的.ssh/authorized_keys文件中,并决定先测试 SSH 登录。令我大吃一惊的是,Putty 在成功登录后立即关闭了连接

我尝试从 Windows PowerShell 进行 ssh 并得到相同的结果(成功登录后立即断开连接)

最后,我尝试使用此登录名进行 sftp...并且一切正常,我仍然保持连接状态

我根本没有为这个用户设置 sftp 限制,所以我不知道是什么原因导致的。

这是我的 /etc/ssh/sshd_config

AcceptEnv LANG LC_*
AllowAgentForwarding no
#AllowGroups sudo
AllowTcpForwarding no
Banner /etc/issue.net
ChallengeResponseAuthentication no
Ciphers [email protected],[email protected],aes256-ctr
ClientAliveCountMax 0
ClientAliveInterval 3600
Compression no
GSSAPIAuthentication no
HostbasedAuthentication no
IgnoreUserKnownHosts yes
Include /etc/ssh/sshd_config.d/*.conf
KerberosAuthentication no
KexAlgorithms [email protected],ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
LogLevel VERBOSE
LoginGraceTime 20
Macs [email protected],[email protected],hmac-sha2-512,hmac-sha2-256
MaxAuthTries 3
MaxSessions 10
MaxStartups 10:30:60
PasswordAuthentication no
PermitEmptyPasswords no
PermitRootLogin no
PermitUserEnvironment no
Port 22
PrintLastLog yes
PrintMotd no
RekeyLimit 512M 1h
StrictModes yes
Subsystem sftp internal-sftp
TCPKeepAlive no
UseDNS no
UsePAM yes
X11Forwarding no

这是唯一包含的其他配置文件:

PermitRootLogin no
DebianBanner no
Protocol 2
LoginGraceTime 10
PasswordAuthentication no
ClientAliveInterval 3600
ClientAliveCountMax 0
AllowUsers ubuntu my-user
X11Forwarding no

最后,这是身份验证后的输出ssh -vvv my-user@myip

debug1: Authentication succeeded (publickey).
Authenticated to XXX.XXX.XXX.XXX ([XXX.XXX.XXX.XXX]:22).
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: network
debug1: console supports the ansi parsing
debug3: Successfully set console output code page from:437 to 65001
debug3: Successfully set console input code page from:437 to 65001
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 4
debug1: Remote: /home/my-user/.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
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
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
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: client_check_window_change: changed
debug2: channel 0: request window-change confirm 0
debug3: send packet: type 98
debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug3: Successfully set console output code page from 65001 to 437
debug3: Successfully set console input code page from 65001 to 437
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

debug3: send packet: type 1
debug3: Successfully set console output code page from 65001 to 437
debug3: Successfully set console input code page from 65001 to 437
Connection to XXX.XXX.XXX.XXX closed.
Transferred: sent 2912, received 2632 bytes, in 0.3 seconds
Bytes per second: sent 8646.7, received 7815.3
debug1: Exit status 1

答案1

经过 2 小时的努力后发布,5 分钟后找到了解决方案,经典..

对于那些可能遇到相同问题的人:请检查您的/etc/passwd文件。此用户的 shell 定义为/bin/false,在 SSH 登录时返回错误。

就我而言,发行版已经强化,并且设置默认值的文件已被修改,以便为新用户/etc/adduser.conf设置 shell 路径。/etc/passwd

相关内容