brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ChannelTimeout makes sshd close SSH sessions that sit idle

Network and access
~/tips/tip-sshd-channeltimeout

ChannelTimeout session=30m direct-tcpip=1h

Log out forgotten shells and stale tunnels after a set time of inactivity.

ClientAliveInterval catches connections that are dead. It does nothing about a shell that is alive and forgotten, open on a laptop in someone’s bag. Since OpenSSH 9.2, sshd can close those too.

In sshd_config:

ChannelTimeout session=30m direct-tcpip=1h
UnusedConnectionTimeout 5m

session=30m closes a shell, command or sftp session after 30 minutes without traffic. direct-tcpip covers local port forwards and SOCKS connections, and there are names for agent, X11 and remote forwards too. global is a special one that looks at all channels together.

UnusedConnectionTimeout then closes the connection itself once it has no open channels left, which is why the two fit together.

Check and reload:

sudo sshd -t && sudo systemctl reload ssh

Some things the man page is clear about. Ending an idle session does not promise that every process from it stops. And a client can simply open a new channel of the same type, so this is tidying up, not a way to enforce rules.

“Idle” means no traffic. A program that keeps printing, like a log tail, keeps the session alive forever, while a quiet editor counts as idle. I would start with generous values and tighten later.

Further reading: sshd_config man page, OpenSSH 9.2 release notes

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link