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