내 VPS가 약 3 개월 동안 재부팅되지 않았습니다. OpenVZ 가상화 유형의 서버에서 호스팅되며 운영 체제는 Ubuntu 16.04입니다. 어떤 이유로 VPS를 재부팅 한 후 ssh를 통해 서버에 연결할 수 없었습니다.받은 메시지는 다음과 같습니다.
ssh: connect to host srvname.com port 22: Connection refused
그래서 VPS에서 시리얼 콘솔을 열고 조사를 시작했습니다 ... 나는 openssh-server
성공적으로 제거하고 다시 설치했습니다 . 인터넷에서 비슷한 문제에 관한 기사, 질문 및 답변을 읽는 데 2 시간을 보냈습니다.
마지막으로 /var/run/sshd
시스템 시작 중에 디렉토리 가 생성되지 않았다는 것을 이해했습니다 . 그리고 일단 수동으로 생성하면 아무런 문제없이 SSH 서비스를 시작할 수 있지만 다음에 재부팅 할 때 문제가 남아 있습니다. 그래서 내 질문은 :
이 문제의 원인은 무엇입니까?
/var/run/sshd
시스템 시작 중에 왜 생성되지 않습니까?올바른 방법으로 문제를 해결하려면 어떻게해야합니까? 이 게시물 끝에 언급 된 일시적인 해결책을 찾았습니다.
문제가 VPS의 OpenVZ 호스트와 관련이 있습니까? 호스팅 제공 업체에 해결을 요청해야합니까?
의 출력 systemctl status ssh.service
, sshd -Ddp 22
및 journalctl -xe
이다 :
# systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since вт 2019-01-15 12:58:08 EET; 22s ago
Process: 407 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)
яну 15 12:58:07 srvname systemd[1]: Failed to start OpenBSD Secure Shell server.
яну 15 12:58:07 srvname systemd[1]: ssh.service: Unit entered failed state.
яну 15 12:58:07 srvname systemd[1]: ssh.service: Failed with result 'exit-code'.
яну 15 12:58:08 srvname systemd[1]: ssh.service: Service hold-off time over, scheduling restart.
яну 15 12:58:08 srvname systemd[1]: Stopped OpenBSD Secure Shell server.
яну 15 12:58:08 srvname systemd[1]: ssh.service: Start request repeated too quickly.
яну 15 12:58:08 srvname systemd[1]: Failed to start OpenBSD Secure Shell server.
яну 15 12:58:08 srvname systemd[1]: ssh.service: Unit entered failed state.
яну 15 12:58:08 srvname systemd[1]: ssh.service: Failed with result 'start-limit-hit'.
# $(which sshd) -Ddp 22
debug1: sshd version OpenSSH_7.2, OpenSSL 1.0.2g 1 Mar 2016
debug1: private host key #0: ssh-rsa SHA256:...
debug1: private host key #1: ssh-dss SHA256:...
debug1: private host key #2: ecdsa-sha2-nistp256 SHA256:...
debug1: private host key #3: ssh-ed25519 SHA256:...
Missing privilege separation directory: /var/run/sshd
# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has begun starting up.
яну 15 13:21:21 srvname sshd[1688]: Missing privilege separation directory: /var/run/sshd
яну 15 13:21:21 srvname systemd[1]: ssh.service: Control process exited, code=exited status=255
яну 15 13:21:21 srvname systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has failed.
--
-- The result is failed.
яну 15 13:21:21 srvname systemd[1]: ssh.service: Unit entered failed state.
яну 15 13:21:21 srvname systemd[1]: ssh.service: Failed with result 'exit-code'.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Service hold-off time over, scheduling restart.
яну 15 13:21:22 srvname systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has finished shutting down.
яну 15 13:21:22 srvname systemd[1]: Starting OpenBSD Secure Shell server...
-- Subject: Unit ssh.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has begun starting up.
яну 15 13:21:22 srvname sshd[1691]: Missing privilege separation directory: /var/run/sshd
яну 15 13:21:22 srvname systemd[1]: ssh.service: Control process exited, code=exited status=255
яну 15 13:21:22 srvname systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has failed.
--
-- The result is failed.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Unit entered failed state.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Failed with result 'exit-code'.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Service hold-off time over, scheduling restart.
яну 15 13:21:22 srvname systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has finished shutting down.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Start request repeated too quickly.
яну 15 13:21:22 srvname systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit ssh.service has failed.
--
-- The result is failed.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Unit entered failed state.
яну 15 13:21:22 srvname systemd[1]: ssh.service: Failed with result 'start-limit-hit'.
의 내용은 다음 /usr/lib/tmpfiles.d/sshd.conf
과 /etc/init/ssh.conf
같습니다.
# cat /usr/lib/tmpfiles.d/sshd.conf
d /var/run/sshd 0755 root root
# cat /etc/init/ssh.conf | sed '/^#/ d'
description "OpenSSH server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
umask 022
env SSH_SIGSTOP=1
expect stop
console none
pre-start script
test -x /usr/sbin/sshd || { stop; exit 0; }
test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
mkdir -p -m0755 /var/run/sshd
end script
exec /usr/sbin/sshd -D
시스템에 대한 추가 정보 :
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
# uname -a
Linux srvname 2.6.32-042stab127.2 #1 SMP Thu Jan 4 16:41:44 MSK 2018 x86_64 x86_64 x86_64 GNU/Linux
# apt show openssh-server | grep 'Version'
Version: 1:7.2p2-4ubuntu2.6
시간적 솔루션 :
그 발견 /var/run
에 대한 심볼릭 링크입니다 /run
, 나는이 필요한 이유를 모르겠지만,이 파일의 내용을 수정하는 경우 /usr/lib/tmpfiles.d/sshd.conf
의를 :
d /var/run/sshd 0755 root root
에:
d /run/sshd 0755 root root
시스템 시작시 모든 것이 잘 작동하고 SSH 서비스가 정상적으로 시작되고 SSH를 통해 로그인 할 수 있습니다.