问题描述:
服务器开机之后发现无法通过远程连接服务器终端,但是服务器并未宕机,于是考虑到sshd服务出现异常
解决思路:
-
查看服务器sshd服务运行情况
[root@haha-main-130 var]# systemctl status sshd -l ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since 三 2022-10-26 10:02:14 EDT; 29s ago Docs: man:sshd(8) man:sshd_config(5) Process: 2089 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=255) Main PID: 2089 (code=exited, status=255) 10月 26 10:02:14 haha-main-130 systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a 10月 26 10:02:14 haha-main-130 systemd[1]: Failed to start OpenSSH server daemon. 10月 26 10:02:14 haha-main-130 systemd[1]: Unit sshd.service entered failed state. 10月 26 10:02:14 haha-main-130 systemd[1]: sshd.service failed.
服务并未正常启动
-
定位问题详细信息
[root@haha-main-130 var]# sshd -t /var/empty/sshd must be owned by root and not group or world-writable.
可以看到输出的信息表示:
/var/empty/sshd
必须是root用户所有,而不是root用户组或全部人都可写入 -
问题处理
查看
/var/empty/sshd
目录权限[root@haha-main-130 var]# ll /var/empty 总用量 0 drwxrwxrwx. 2 root root 6 8月 8 2019 sshd
由于之前调试原因,将
/var
目录所有的权限都调整成了777,所以造成sshd无法启动 -
修改目录权限
[root@haha-main-130 var]# chmod -Rf 755 /var/empty/sshd/ [root@haha-main-130 var]# ll /var/empty 总用量 0 drwxr-xr-x. 2 root root 6 8月 8 2019 sshd
-
重新启动服务
[root@haha-main-130 var]# systemctl restart sshd [root@haha-main-130 var]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 三 2022-10-26 10:13:11 EDT; 6s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 2150 (sshd) CGroup: /system.slice/sshd.service └─2150 /usr/sbin/sshd -D 10月 26 10:13:11 haha-main-130 sshd[2150]: Server listening on 0.0.0.0 port 22. 10月 26 10:13:11 haha-main-130 systemd[1]: Stopped OpenSSH server daemon. 10月 26 10:13:11 haha-main-130 sshd[2150]: Server listening on :: port 22. 10月 26 10:13:11 haha-main-130 systemd[1]: Starting OpenSSH server daemon... 10月 26 10:13:11 haha-main-130 systemd[1]: Started OpenSSH server daemon. Hint: Some lines were ellipsized, use -l to show in full.
sshd服务可以正常启动