# \[Solved\] SSH session getting dropped overnight

**URL:** <https://forum.openwrt.org/t/solved-ssh-session-getting-dropped-overnight/255562>\
**Category:** Installing and Using OpenWrt\
**Created:** [November 17, 2026, 8:50am UTC](https://forum.openwrt.org/t/solved-ssh-session-getting-dropped-overnight/255562 "2026-11-17T08:50:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghewson](https://forum.openwrt.org/letter_avatar/ghewson/32/6_449c533f586939b6e5f246632a46421f.png) [@ghewson](https://forum.openwrt.org/u/ghewson)\
**Post date:** [November 17, 2026, 8:50am UTC](https://forum.openwrt.org/t/solved-ssh-session-getting-dropped-overnight/255562/1 "2026-11-17T08:50:14Z")

</div>

I wanted to start an SSH session to my OpenWrt router, sleep (S3) the client host overnight, and return to the SSH session the next day. However, I found that OpenWrt (specifically Dropbear) had closed the session.

I set the [Dropbear SSHKeepAlive interval](https://openwrt.org/docs/guide-user/base-system/dropbear#sections) to 21600 seconds (6 hours), and 3 times that should have given plenty of time to avoid the timeout, but it didn't. With double the setting (12 hours), the result was unchanged.

Testing by sleeping the client host immediately after starting the SSH session and examining the OpenWrt log, I found that the interval between these messages:

```plaintext
authpriv.info: dropbear[7850]: Child connection from xx.xx.xx.xx:nnnnn
authpriv.notice: dropbear[7850]: Password auth succeeded for 'root' from xx.xx.xx.xx:nnnnn

```

and this message:

```plaintext
authpriv.info: dropbear[7850]: Exit (root) from <xx.xx.xx.xx:nnnnn>: Error reading: Host is unreachable

```

was 8 hours plus about 15 minutes. There was no relation to the SSHKeepAlive interval I'd set.

Using the [OpenSSH -v option](https://man.openbsd.org/ssh#v) on the client gave some more clues about what was going on. After a little over 8 hours:

```plaintext
root@openwrt:~# debug1: SSH2_MSG_KEXINIT received
debug1: SSH2_MSG_KEXINIT sent
debug1: kex: algorithm: sntrup761x25519-sha512
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: rekeying in progress
debug1: rekeying in progress
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:byuVT7M+p+mss4HewLoIFA61qD/8CzeKZGIMw8h3jTc
debug1: ssh_packet_send2_wrapped: resetting send seqnr 11
debug1: ssh_set_newkeys: rekeying out, input 5032 bytes 413 blocks, output 6244 bytes 426 blocks
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: ssh_packet_read_poll2: resetting read seqnr 15
debug1: SSH2_MSG_NEWKEYS received
debug1: ssh_set_newkeys: rekeying in, input 5052 bytes 415 blocks, output 6244 bytes 0 blocks
debug1: rekey in after 134217728 blocks

```

This shows that Dropbear has an undocumented feature, "rekeying" of the SSH session. The relevant code is in `common-session.c`:

```plaintext
    if (!ses.kexstate.sentkexinit
            && (elapsed(now, ses.kexstate.lastkextime) >= KEX_REKEY_TIMEOUT
            || ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA
            || ses.kexstate.needrekey)) {
        TRACE(("rekeying after timeout or max data reached"))
        ses.kexstate.needrekey = 0;
        send_msg_kexinit();
    }

```

and `sysoptions.h`:

```plaintext
/* Spec recommends after one hour or 1 gigabyte of data. One hour
 * is a bit too verbose, so we try 8 hours */
#ifndef KEX_REKEY_TIMEOUT
#define KEX_REKEY_TIMEOUT (3600 * 8)
#endif
#ifndef KEX_REKEY_DATA
#define KEX_REKEY_DATA (1<<30) /* 2^30 == 1GB, this value must be < INT_MAX */
#endif

```

The spec it refers to is RFC 4253, "The Secure Shell (SSH) Transport Layer Protocol", which uses the term "Key Re-Exchange" in [section 9](https://www.rfc-editor.org/info/rfc4253/#section-9). The relevant part says:

```plaintext
   It is RECOMMENDED that the keys be changed after each gigabyte of
   transmitted data or after each hour of connection time, whichever
   comes sooner. However, since the re-exchange is a public key
   operation, it requires a fair amount of processing power and should
   not be performed too often.

```

Perhaps less attention need be given to the second sentence of the paragraph now, 20 years after the RFC was published. Still, Dropbear changes the keys after 8 hours.

It's interesting to note that by default OpenSSH (server or client) [doesn't use time-based rekeying](https://man.openbsd.org/sshd_config#RekeyLimit).

So I'd solved the mystery (as it appeared to me) of why the SSH sessions were dropping out. What to do? I considered recompiling Dropbear with a modification to the timeout, or [replacing Dropbear with OpenSSH](https://openwrt.org/docs/guide-user/services/ssh/openssh_instead_dropbear). I decided to do neither, and just live with the problem.

This all took place on my own LAN, where although I'm aware of the need for security, I'm less concerned about it than I am about traffic on the Internet. SSH rekeying is a [security feature](https://security.stackexchange.com/questions/74634/whats-the-importance-of-sshds-setting-rekeylimit), and if I wanted to use a prolonged SSH session on the Internet, I'd certainly consider enabling time-based rekeying in OpenSSH, or use dbclient, the Dropbear client.

---

<div class="post-metadata">

**Author:** ![DBAA](https://forum.openwrt.org/letter_avatar/dbaa/32/6_449c533f586939b6e5f246632a46421f.png) [@DBAA](https://forum.openwrt.org/u/DBAA)\
**Post date:** [November 17, 2026, 5:27pm UTC](https://forum.openwrt.org/t/solved-ssh-session-getting-dropped-overnight/255562/2 "2026-11-17T17:27:35Z")

</div>

Usually use a terminal multiplexer like `tmux` so a shell's lifetime is not tied to a connection. Then if the SSH session drops or is terminated etc. I can reconnect and do `tmux attach` to get the shell back.
