0

Idle is defined as when no foreground program is running and the terminal is waiting for user input, but the user does not make any input.

Actually, my ultimate goal is: shutdown when all SSH sessions are idle and x-window is also idle.
The idle time of x-window can be determined with xprintidle. So for now I just need to determine if all SSH sessions are idle or not.
I've looked for many ways to determine if a machine is idle in Linux, but most of them are based on x-window to determine if the desktop is idle.

  • There used to be a program called `timeoutd` which would log out users who had been idle for a configurable amount of time. It used to be pretty popular to stop users from hogging scarce resources like modem dial-in lines. I haven't seen it for many years and I don't think it's maintained any more. Anyway if you could find that and recompile it for a modern distro (or find an alternative that does the same thing), you could shutdown when there are no ssh sessions logged in. – cas Oct 20 '21 at 15:32

1 Answers1

0

in /etc/ssh/sshd_config

# default values
ClientAliveInterval                        0
ClientAliveCountMax                        3

If you set ClientAliveInterval to 600 {seconds} along with ClientAliveCountMax to 0 then that will close any SSH session that has been idle for 10 minutes. By using this mechanism you could have any SSH session cleanly close after a specific timeout or idle period of your choosing. Then check to see if there are any SSH sessions or processes present and if not then do a shutdown.

Recommend you also read up on those two SSH parameters before using them to be sure,

https://man.openbsd.org/sshd_config

What do options `ServerAliveInterval` and `ClientAliveInterval` in sshd_config do exactly?

ron
  • 5,749
  • 7
  • 48
  • 84