短時間後、centos 7 SSH 接続が終了しました。

短時間後、centos 7 SSH 接続が終了しました。

SSH経由でCentOS 7サーバーに接続しようとすると、接続時にユーザー名とパスワードの入力が求められます。しかし、しばらくすると接続が切断され、応答がありません。その後、サーバーコンソールに移動してインターネットのどこにでもpingを送信し(時にはネットワークを再起動する必要があります)、成功します。その後、クライアントからSSH接続を再試行すると再接続されますが、短時間で接続が再び閉じられます。

systemctl status networkを使用してネットワークの状態を確認するとき:

network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: active (exited) since Thu 2022-02-17 10:28:03 +03; 43min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4314 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 4551 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
    Tasks: 0

設定が終了したのはなぜですか?また、プリセット:無効にすると問題が発生しますか?イーサネット接続の構成は次のとおりです。

DEVICE=ens18
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=<hw mac address hidden>
IPADDR=<server ip hidden>
NETMASK=255.255.255.192
GATEWAY=<gateway ip hidden>
DNS1=<dns ip hidden>
DNS2=<dns ip hidden>
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=ens18

SSHクライアントログ:

$ ssh root@<server ip> -v
OpenSSH_7.7p1, OpenSSL 1.0.2p  14 Aug 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to <server ip> [<server ip>] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/serhat/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to <server ip>:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:MiFljnjU0tNBZzpOa2tl5oean+77W4wZ1/cy8f2ULeU
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:MiFljnjU0tNBZzpOa2tl5oean+77W4wZ1/cy8f2ULeU.
Please contact your system administrator.
Add correct host key in /c/Users/serhat/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/serhat/.ssh/known_hosts:3
ECDSA host key for <server ip> has changed and you have requested strict checking.
Host key verification failed.

ベストアンサー1

SSHでは、一定期間アクティビティがないと(クライアントとサーバー間の通信はありません)、サーバーは接続を閉じることができます。クライアント設定またはサーバー設定でこの動作を処理できます。

クライアント側で ~/.ssh/config ファイルを編集します (存在しない場合は作成)。

Host *
    ServerAliveInterval 240

ServerAliveInterval は、クライアントがサーバーにシグナルを送信した後の時間を指定します。

サーバーへのアクセス権がある場合は、/etc/ssh/sshd_config ファイルを変更できます。

ClientAliveInterval 300
ClientAliveCountMax 10

これにより、サーバーはアクティビティがないたびに5分ごとにクライアントにシグナルを送信します。接続を閉じる前にこれを10回実行してください。

おすすめ記事