Commands.page Logo

What Happens to Sudo Credentials When Closing Terminal Ubuntu

When you close the terminal window in Ubuntu, your cached sudo credentials are invalidated for that specific session. This means if you open a new terminal window and attempt to run a command with sudo privileges, you will be prompted to enter your password again. This article explains the mechanism behind sudo credential caching, how terminal sessions affect authentication, and the default timeout settings involved.

Sudo Timestamp Mechanism

Ubuntu uses a timestamp file to track when you last successfully entered your sudo password. By default, this timestamp is valid for 15 minutes. Within this window, you can run multiple sudo commands without re-entering your password. However, this caching behavior is tied to specific session parameters rather than just the user account globally.

Terminal Session and TTY Tickets

The sudo configuration in Ubuntu typically enables a feature called tty_tickets. This setting ties the authentication timestamp to the specific terminal device (TTY) you are using. When you close a terminal window, that TTY session ends. Consequently, the cached credentials associated with that TTY are no longer accessible.

Opening a New Terminal

When you launch a new terminal window, you are assigned a new TTY. Because tty_tickets is enabled by default, the new terminal does not inherit the sudo timestamp from the closed terminal. You must authenticate again to establish a new timestamp for the new session. This security measure ensures that privileged access does not persist indefinitely across different shell instances.

Default Timeout Behavior

If you keep the same terminal window open but stop using sudo commands, the credentials will eventually expire after the default 15-minute period. Closing the terminal forces an immediate expiration for that session path. You can modify these settings in the /etc/sudoers file, but the default behavior is designed to balance convenience with system security.