启动 sshd 时 systemctl 挂起,但“/usr/sbin/sshd -D -f /etc/ssh/sshd_config &”可以工作

启动 sshd 时 systemctl 挂起,但“/usr/sbin/sshd -D -f /etc/ssh/sshd_config &”可以工作

CentOS 7.这是 /usr/lib/systemd/system/sshd.service

[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

sshd_config 中未注释的所有内容:

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile.ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
usePAM no # Had to change it to no from yes because the connection was dropping right after successfull auth
X11Forwarding yes
Subsystemsftp/usr/libexec/openssh/sftp-server

如果需要的话我很乐意提供任何其他东西。感谢您的帮助!

答案1

看起来你的sshd_config

Subsystemsftp/usr/libexec/openssh/sftp-server

应该

Subsystem sftp /usr/libexec/openssh/sftp-server

和这个

AuthorizedKeysFile.ssh/authorized_keys

应该

AuthorizedKeysFile .ssh/authorized_keys

此外,对你的配置进行语法检查

sshd -t 

相关内容