
ARMなSingle Board Computerを弄っていると、そのボードの非力さから時々以下のようなエラーになることがあります。
packet_write_wait: Connection to <IP Address> port 22: Broken pipe
SSH接続をしながら色々と作業していると、CPUが非力ゆえにsshdが接続を維持できなくて上記のようなエラーで接続断が発生します。
というわけで対応するための設定をしておきます。
Webの情報
ちなみにこの手の記事は多くみられます。



SSHサーバ側
SSHサーバ側は以下のパラメータが有効のようです。
ClientAliveInterval 30
ClientAliveCountMax 5
上記の場合は、接続クライアントに対して30秒間隔で5回まで応答確認を行います。これを超えたときに接続タイムアウトになります。
あと、sshdサービスの再起動をしておきましょう。
ClientAliveCountMax
Sets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different fromTCPKeepAlive
. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled byTCPKeepAlive
is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive. The default value is 3. IfClientAliveInterval
is set to 15, andClientAliveCountMax
is left at the default, unresponsive SSH clients will be disconnected after approximately 45 secondshttps://man.openbsd.org/sshd_config
ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.
SSHクライアント側
クライアント側は以下の設定パラメータがあります。
ServerAliveInterval 15
ServerAliveCountMax 10
15秒ごとに10回応答確認をサーバに送り、 それを超えた場合にタイムアウトになります。
ServerAliveCountMax
Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different fromTCPKeepAlive
(below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled byTCPKeepAlive
is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive. The default value is 3. If, for example,ServerAliveInterval
(see below) is set to 15 andServerAliveCountMax
is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 secondshttps://man.openbsd.org/ssh_config
ServerAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.
SSHはほぼ必須な手順ですが、設定についてはあんまり分かっていませんでした。他にもKeepAliveとかも良く使われますが、もうちょっとパラメータについて勉強しておいた方が良いかな、と改めて思いました。