SUDOERS_TIMESTAMP(5)
๐ SUDOERS_TIMESTAMP(5) ๐ โ the File Formats Manual entry, bestie edition
okay so this is sudoers_timestamp from the File Formats Manual section, and I need you to know it's giving deep lore. This is the page about how sudo remembers that you already typed your password so it doesn't make you do it again five seconds later. Iconic behaviour, honestly.
โจ NAME โจ
sudoers_timestamp โ Sudoers Time Stamp Format
Like. The name is the whole plot. It's the format. Of the time stamps. Slay.
๐ DESCRIPTION ๐
The sudoers plugin uses per-user-ID time stamp files for credential caching. Once a user has been authenticated, they may use sudo without a password for a short period of time โ 5 minutes unless overridden by the timestamp_timeout option. Yes bestie, five minutes of freedom, use them wisely.
By default, sudoers uses a separate record for each terminal, which means that a user's login sessions are authenticated separately. The timestamp_type option can be used to select the type of time stamp record sudoers will use.
A multi-record time stamp file format was introduced in sudo 1.8.10 that uses a single file per user. Previously, a separate file was used for each user and terminal combination unless tty-based time stamps were disabled. The new format is extensible and records of multiple types and versions may coexist within the same file. Coexisting?? In this economy?? We love to see it.
All records, regardless of type or version, begin with a 16-bit version number and a 16-bit record size. Every single one. No exceptions. It's a vibe check at the door.
Time stamp records have the following structure:
/* Time stamp entry types */
#define TS_GLOBAL 0x01U /* not restricted by tty or ppid */
#define TS_TTY 0x02U /* restricted by tty */
#define TS_PPID 0x03U /* restricted by ppid */
#define TS_LOCKEXCL 0x04U /* special lock record */
/* Time stamp flags */
#define TS_DISABLED 0x01U /* entry disabled */
#define TS_ANYUID 0x02U /* ignore uid, only valid in key */
struct timestamp_entry {
unsigned short version; /* version number */
unsigned short size; /* entry size */
unsigned short type; /* TS_GLOBAL, TS_TTY, TS_PPID */
unsigned short flags; /* TS_DISABLED, TS_ANYUID */
uid_t auth_uid; /* uid to authenticate as */
pid_t sid; /* session ID associated with tty/ppid */
struct timespec start_time; /* session/ppid start time */
struct timespec ts; /* time stamp (CLOCK_MONOTONIC) */
union {
dev_t ttydev; /* tty device number */
pid_t ppid; /* parent pid */
} u;
};
The timestamp_entry struct fields are as follows, and yes I'm going through every single one because you deserve the full picture:
versionโ The version number of thetimestamp_entrystruct. New entries are created with a version number of2. Records with different version numbers may coexist in the same file but are not inter-operable. They're roommates who don't speak.sizeโ The size of the record in bytes. Just the size. That's it. That's the field.typeโ The record type, currentlyTS_GLOBAL,TS_TTY, orTS_PPID.flagsโ Zero or more record flags which can be bit-wise ORed together. Supported flags areTS_DISABLED, for records disabled viasudo -k, andTS_ANYUID, which is used only when matching records.auth_uidโ The user-ID that was used for authentication. Depending on the value of therootpw,runaspwandtargetpwoptions, the user-ID may be that of the invoking user, therootuser, the default runas user or the target user. So like, it depends, and that's on options.sidโ The ID of the user's terminal session, if present. The session ID is only used when matching records of typeTS_TTY.start_timeโ The start time of the session leader for records of typeTS_TTYor of the parent process for records of typeTS_PPID. Thestart_timeis used to help prevent reuse of a time stamp record after a user has logged out. Heads up though: not all systems support a method to easily retrieve a process's start time. Thestart_timefield was added insudoersversion 1.8.22 for the second revision of thetimestamp_entrystruct.tsโ The actual time stamp. A monotonic time source (which does not move backward) is used if the system supports it. Where possible,sudoersuses a monotonic timer that increments even while the system is suspended. The value oftsis updated each time a command is run viasudo. If the difference betweentsand the current time is less than the value of thetimestamp_timeoutoption, no password is required. The dream, fr fr.u.ttydevโ The device number of the terminal associated with the session for records of typeTS_TTY.u.ppidโ The ID of the parent process for records of typeTS_PPID.
Also, the tsdump utility, included with the sudo source distribution, can be used to display the contents of a sudoers time stamp file. It's giving x-ray vision for time stamps. Obsessed.
๐ LOCKING ๐
In sudoers versions 1.8.10 through 1.8.14, the entire time stamp file was locked for exclusive access when reading or writing to the file. Starting in sudoers 1.8.15, individual records are locked in the time stamp file instead of the entire file and the lock is held for a longer period of time. This scheme is described below. Character development, honestly.
The first record in the time stamp file is of type TS_LOCKEXCL and is used as a lock record to prevent more than one sudo process from adding a new record at the same time. Once the desired time stamp record has been located or created (and locked), the TS_LOCKEXCL record is unlocked. The lock on the individual time stamp record, however, is held until authentication is complete. This allows sudoers to avoid prompting for a password multiple times when it is used more than once in a pipeline. So thoughtful of her.
Records of type TS_GLOBAL cannot be locked for a long period of time since doing so would interfere with other sudo processes. Instead, a separate lock record is used to prevent multiple sudo processes using the same terminal (or parent process ID) from prompting for a password as the same time.
๐ SEE ALSO ๐
๐ฆ HISTORY ๐ฆ
Originally, sudo used a single zero-length file per user and the file's modification time was used as the time stamp. (Zero bytes. No content. Just vibes and a mtime.) Later versions of sudo added restrictions on the ownership of the time stamp files and directory as well as checks on the validity of the time stamp itself. Notable changes were introduced in the following sudo versions:
1.4.0โ Support for tty-based time stamp file was added by appending the terminal name to the time stamp file name.1.6.2โ The time stamp file was replaced by a per-user directory which contained any tty-based time stamp files.1.6.3p2โ The target user name was added to the time stamp file name when thetargetpwoption was set.1.7.3โ Information about the terminal device was stored in tty-based time stamp files for validity checks. This included the terminal device numbers, inode number and, on systems where it was not updated when the device was written to, the inode change time. This helped prevent reuse of the time stamp file after logout.1.8.6p7โ The terminal session ID was added to tty-based time stamp files to prevent reuse of the time stamp by the same user in a different terminal session. It also helped prevent reuse of the time stamp file on systems where the terminal device's inode change time was updated by writing.1.8.10โ A new, multi-record time stamp file format was introduced that uses a single file per user. The terminal device's change time was not included since most systems now update the change time after a write is performed as required by POSIX.1.8.15โ Individual records are locked in the time stamp file instead of the entire file and the lock is held until authentication is complete.1.8.22โ The start time of the terminal session leader or parent process is now stored in non-global time stamp records. This prevents reuse of the time stamp file after logout in most cases.- Support was added for the kernel-based tty time stamps available in OpenBSD which do not use an on-disk time stamp file. No file, no problem.
1.9.15โ Time stamp file path names are now based on the invoking user-ID instead of the user name. This avoids problems with user names that include a path separator character. (iykyk, a/in a username is a whole situation.)
๐ AUTHORS ๐
Many people have worked on sudo over the years; this version consists of code written primarily by:
Todd C. Miller
See the CONTRIBUTORS.md file in the sudo distribution (<https://www.sudo.ws/about/contributors/>) for an exhaustive list of people who have contributed to sudo. An exhaustive list!! The whole group chat showed up.
๐ BUGS ๐
If you believe you have found a bug in sudoers_timestamp, you can either file a bug report in the sudo bug database, <https://bugzilla.sudo.ws/>, or open an issue at <https://github.com/sudo-project/sudo/issues>. If you would prefer to use email, messages may be sent to the sudo-workers mailing list, <https://www.sudo.ws/mailman/listinfo/sudo-workers> (public) or <sudo@sudo.ws> (private).
โ ๏ธ Please do not report security vulnerabilities through public GitHub issues, Bugzilla or mailing lists. Instead, report them via email to <Todd.Miller@sudo.ws>. You may encrypt your message with PGP if you would like, using the key found at <https://www.sudo.ws/dist/PGPKEYS>. This one is serious, bestie โ private channel only, no public posting.
๐ซถ SUPPORT ๐ซถ
Limited free support is available via the sudo-users mailing list, see <https://www.sudo.ws/mailman/listinfo/sudo-users> to subscribe or search the archives.
๐ธ DISCLAIMER ๐ธ
sudo is provided โAS ISโ and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. See the LICENSE.md file distributed with sudo or <https://www.sudo.ws/about/license/> for complete details.
and that's the whole page, no notes ๐ this was Sudo 1.9.17p2, November 26, 2023 โ mwah, take care of your time stamps, they're doing their best out here ๐โจ
๐ฆ where this page comes from
- alpine 3.24: sudo-doc 1.9.17_p2-r2 ยท custom ISC
- arch rolling: sudo 1.9.17.p2-6 ยท custom
- centos-stream 10: sudo 1.9.17-13.p2.el10 ยท ISC
- centos-stream 9: sudo 1.9.17p2-6.el9 ยท ISC
- fedora 43: sudo 1.9.17-7.p2.fc43 ยท ISC
- fedora 44: sudo 1.9.17-10.p2.fc44 ยท ISC
- fedora 44: sudo 1.9.17-7.p2.fc44 ยท ISC
- nixos 26.05: sudo 1.9.17p2
- nixpkgs unstable: sudo 1.9.17p2
- ๐ the page's license: ISC
- Copyright (c) 2017-2020, 2022-2023 Todd C. Miller <Todd.Miller@sudo.ws>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms