How to Stop Ubuntu Linux from Automatically Logging Out

The Idle Session Disconnect

If you leave your Ubuntu computer unattended for an extended period, you might return to find that all your applications have been closed and you are staring at the main login screen. Ubuntu has automatically logged you out of your desktop session. This is a severe security feature often enforced in enterprise environments or on shared machines to ensure that if a user walks away, their sensitive data isn’t left exposed. However, on a personal home computer or a dedicated rendering workstation, this automatic logout behavior destroys productivity, abruptly killing long-running tasks, unsaved documents, and active terminal sessions.

How to Disable Auto-Logout in GNOME Desktop

If you are using the standard Ubuntu graphical desktop (GNOME), the automatic logout is controlled by a hidden system setting that you cannot access from the standard Settings menu. You must use the terminal to alter the GNOME session behavior.

1. Open your terminal application (Ctrl+Alt+T).

2. The setting is managed by `gsettings`. Run the following command to check the current auto-logout delay (the value is in seconds):

gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout

3. To completely disable the automatic logout/sleep function when your computer is plugged into wall power, set the timeout value to 0 (zero):

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0

4. If you are using a laptop, you must also disable the feature for when the machine is running on battery power:

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 0

Once these values are set to zero, the GNOME desktop environment will never terminate your session due to inactivity.

How to Disable Auto-Logout for SSH / Terminal Sessions

If you are managing an Ubuntu Server remotely via SSH, you might find your connection automatically drops and logs you out after a few minutes of not typing.

This is controlled by the SSH daemon or the shell profile.

1. To prevent the SSH server from dropping idle connections, edit the SSH config file:

sudo nano /etc/ssh/sshd_config

2. Scroll down and find (or add) the following two lines. This tells the server to send a “keep-alive” ping every 120 seconds, and to never disconnect the client:

ClientAliveInterval 120
ClientAliveCountMax 720

3. Save the file (Ctrl+O) and exit (Ctrl+X).

4. Restart the SSH service to apply the changes:

sudo systemctl restart sshd

Your remote terminal session will now remain active indefinitely, allowing you to leave scripts running without fear of being automatically logged out.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.