ServerAliveInterval is the client side of keeping an SSH session honest. The same idea exists on the server, and it is the one that cleans up after laptops that went to sleep.
In sshd_config, ClientAliveInterval sets a timeout in seconds. If sshd has received no data from the client for that long, it sends a message through the encrypted channel and asks for a response. The default is 0, which means no such messages are sent. ClientAliveCountMax is how many of these messages may go unanswered before sshd disconnects the client; the default is 3.
# /etc/ssh/sshd_config.d/20-alive.conf
ClientAliveInterval 60
ClientAliveCountMax 3
With those two lines, a client that disappears is disconnected after roughly 60 seconds times 3, so about three minutes. With the default of 0 sshd sends none of these messages, so it has no timer of its own to notice that the client is gone.
Test the file before you reload, and keep your current session open until a new login works:
sudo sshd -t
sudo systemctl reload ssh
On some distributions the unit is called sshd instead of ssh.
There is a caveat that bites people on flaky connections. A short interval combined with a low count means little patience, so a brief network hiccup, for example on mobile data or train Wi-Fi, can cost you the session. If that is your situation, raise the count. The setting is meant for connections where the client has stopped answering, which is a different problem from a session that is merely idle.
The client-side counterpart is ServerAliveInterval in your own ssh config, which lets your ssh notice a dead server.
Further reading: sshd_config(5)