1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
|
.\" Copyright, the authors of the Linux man-pages project
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.\"
.TH utmp 5 2025-05-17 "Linux man-pages (unreleased)"
.SH NAME
utmp, wtmp \- login records
.SH SYNOPSIS
.nf
.B #include <utmp.h>
.fi
.SH DESCRIPTION
The
.I utmp
file allows one to discover information about who is currently using the
system.
There may be more users currently using the system, because not
all programs use utmp logging.
.P
.B Warning:
.I utmp
must not be writable by the user class "other",
because many system programs (foolishly)
depend on its integrity.
You risk faked system logfiles and
modifications of system files if you leave
.I utmp
writable to any user other than the owner and group owner of the file.
.P
The file is a sequence of
.I utmp
structures,
declared as follows in
.I <utmp.h>
(note that this is only one of several definitions
around; details depend on the version of libc):
.P
.in +4n
.EX
/* Values for ut_type field, below */
\&
#define EMPTY 0 /* Record does not contain valid info
(formerly known as UT_UNKNOWN on Linux) */
#define RUN_LVL 1 /* Change in system run\-level (see
\c
.BR init (1))\ \c
*/
#define BOOT_TIME 2 /* Time of system boot (in \f[I]ut_tv\f[]) */
#define NEW_TIME 3 /* Time after system clock change
(in \f[I]ut_tv\f[]) */
#define OLD_TIME 4 /* Time before system clock change
(in \f[I]ut_tv\f[]) */
#define INIT_PROCESS 5 /* Process spawned by \c
.BR init (1)\ \c
*/
#define LOGIN_PROCESS 6 /* Session leader process for user login */
#define USER_PROCESS 7 /* Normal process */
#define DEAD_PROCESS 8 /* Terminated process */
#define ACCOUNTING 9 /* Not implemented */
\&
#define UT_LINESIZE 32
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
\&
struct exit_status { /* Type for ut_exit, below */
short e_termination; /* Process termination status */
short e_exit; /* Process exit status */
};
\&
struct utmp {
short ut_type; /* Type of record */
pid_t ut_pid; /* PID of login process */
char ut_line[UT_LINESIZE]; /* Device name of tty \- "/dev/" */
char ut_id[4]; /* Terminal name suffix,
or inittab(5) ID */
char ut_user[UT_NAMESIZE]; /* Username */
char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
kernel version for run\-level
messages */
struct exit_status ut_exit; /* Exit status of a process
marked as DEAD_PROCESS; not
used by Linux \c
.BR init (1)\ \c
*/
/* The ut_session and ut_tv fields must be the same size when
compiled 32\- and 64\-bit. This allows data files and shared
memory to be shared between 32\- and 64\-bit applications. */
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
int32_t ut_session; /* Session ID (\c
.BR getsid (2) ),
used for windowing */
struct {
int32_t tv_sec; /* Seconds */
int32_t tv_usec; /* Microseconds */
} ut_tv; /* Time entry was made */
#else
long ut_session; /* Session ID */
struct timeval ut_tv; /* Time entry was made */
#endif
\&
int32_t ut_addr_v6[4]; /* Internet address of remote
host; IPv4 address uses
just ut_addr_v6[0] */
char __unused[20]; /* Reserved for future use */
};
\&
/* Backward compatibility hacks */
#define ut_name ut_user
#ifndef _NO_UT_TIME
#define ut_time ut_tv.tv_sec
#endif
#define ut_xtime ut_tv.tv_sec
#define ut_addr ut_addr_v6[0]
.EE
.in
.P
This structure gives the name of the special file associated with the
user's terminal, the user's login name, and the time of login in the form
of
.BR time (2).
String fields are terminated by a null byte (\[aq]\[rs]0\[aq])
if they are shorter than the size
of the field.
.P
The first entries ever created result from
.BR init (1)
processing
.BR inittab (5).
Before an entry is processed, though,
.BR init (1)
cleans up utmp by setting
.I ut_type
to
.BR DEAD_PROCESS ,
clearing
.IR ut_user ,
.IR ut_host ,
and
.I ut_time
with null bytes for each
record which
.I ut_type
is not
.B DEAD_PROCESS
or
.B RUN_LVL
and where no process with PID
.I ut_pid
exists.
If no empty record
with the needed
.I ut_id
can be found,
.BR init (1)
creates a new one.
It sets
.I ut_id
from the inittab,
.I ut_pid
and
.I ut_time
to the current values,
and
.I ut_type
to
.BR INIT_PROCESS .
.P
.BR mingetty (8)
(or
.BR agetty (8))
locates the entry by the PID, changes
.I ut_type
to
.BR LOGIN_PROCESS ,
changes
.IR ut_time ,
sets
.IR ut_line ,
and waits
for connection to be established.
.BR login (1),
after a user has been
authenticated, changes
.I ut_type
to
.BR USER_PROCESS ,
changes
.IR ut_time ,
and sets
.I ut_host
and
.IR ut_addr .
Depending on
.BR mingetty (8)
(or
.BR agetty (8))
and
.BR login (1),
records may be located by
.I ut_line
instead of the preferable
.IR ut_pid .
.P
When
.BR init (1)
finds that a process has exited, it locates its utmp entry by
.IR ut_pid ,
sets
.I ut_type
to
.BR DEAD_PROCESS ,
and clears
.IR ut_user ,
.IR ut_host ,
and
.I ut_time
with null bytes.
.P
.BR xterm (1)
and other terminal emulators directly create a
.B USER_PROCESS
record and generate the
.I ut_id
by using the
string that suffix part of the terminal name (the characters
following
.IR /dev/ [pt] ty ).
If they find a
.B DEAD_PROCESS
for this ID,
they recycle it, otherwise they create a new entry.
If they can, they
will mark it as
.B DEAD_PROCESS
on exiting and it is advised that
they null
.IR ut_line ,
.IR ut_time ,
.IR ut_user ,
and
.I ut_host
as well.
.P
.BR telnetd (8)
sets up a
.B LOGIN_PROCESS
entry and leaves the rest to
.BR login (1)
as usual.
After the telnet session ends,
.BR telnetd (8)
cleans up utmp in the described way.
.P
The
.I wtmp
file records all logins and logouts.
Its format is exactly like
.I utmp
except that a null username
indicates a logout
on the associated terminal.
Furthermore, the terminal name
.B \[ti]
with username
.B shutdown
or
.B reboot
indicates a system shutdown or reboot
and the pair of terminal names
.BR | / }
logs the old/new system time when
.BR date (1)
changes it.
.I wtmp
is maintained by
.BR login (1),
.BR init (1),
and some versions of
.BR getty (8)
(e.g.,
.BR mingetty (8)
or
.BR agetty (8)).
None of these programs creates the file, so if it is
removed, record-keeping is turned off.
.SH FILES
.I /var/run/utmp
.br
.I /var/log/wtmp
.SH VERSIONS
POSIX.1 does not specify a
.I utmp
structure, but rather one named
.I utmpx
(as part of the XSI extension),
with specifications for the fields
.IR ut_type ,
.IR ut_pid ,
.IR ut_line ,
.IR ut_id ,
.IR ut_user ,
and
.IR ut_tv .
POSIX.1 does not specify the lengths of the
.I ut_line
and
.I ut_user
fields.
.P
Linux defines the
.I utmpx
structure to be the same as the
.I utmp
structure.
.SH STANDARDS
Linux.
.SH HISTORY
Linux utmp entries conform neither to v7/BSD nor to System V; they are a
mix of the two.
.P
v7/BSD has fewer fields; most importantly it lacks
.IR ut_type ,
which causes native v7/BSD-like programs to display (for
example) dead or login entries.
Further, there is no configuration file
which allocates slots to sessions.
BSD does so because it lacks
.I ut_id
fields.
.P
In Linux (as in System V), the
.I ut_id
field of a
record will never change once it has been set, which reserves that slot
without needing a configuration file.
Clearing
.I ut_id
may result
in race conditions leading to corrupted utmp entries and potential
security holes.
Clearing the abovementioned fields by filling them
with null bytes is not required by System V semantics,
but makes it possible to run
many programs which assume BSD semantics and which do not modify utmp.
Linux uses the BSD conventions for line contents, as documented above.
.P
.\" mtk: What is the referrent of "them" in the following sentence?
.\" System V only uses the type field to mark them and logs
.\" informative messages such as \f[B]"new time"\f[] in the line field.
System V has no
.I ut_host
or
.I ut_addr_v6
fields.
.SH NOTES
Unlike various other
systems, where utmp logging can be disabled by removing the file, utmp
must always exist on Linux.
If you want to disable
.BR who (1),
then do not make utmp world readable.
.P
The file format is machine-dependent, so it is recommended that it be
processed only on the machine architecture where it was created.
.P
Note that on
.I biarch
platforms, that is, systems which can run both
32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),
.I ut_tv
is the same size in 32-bit mode as in 64-bit mode.
The same goes for
.I ut_session
and
.I ut_time
if they are present.
This allows data files and shared memory to be shared between
32-bit and 64-bit applications.
This is achieved by changing the type of
.I ut_session
to
.IR int32_t ,
and that of
.I ut_tv
to a struct with two
.I int32_t
fields
.I tv_sec
and
.IR tv_usec .
Since
.I ut_tv
may not be the same as
.IR struct\~timeval ,
then instead of the call:
.P
.in +4n
.EX
gettimeofday((struct timeval *) &ut.ut_tv, NULL);
.EE
.in
.P
the following method of setting this field is recommended:
.P
.in +4n
.EX
struct utmp ut;
struct timeval tv;
\&
gettimeofday(&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
.EE
.in
.\" .P
.\" Note that the \f[I]utmp\f[] struct from libc5 has changed in libc6.
.\" Because of this,
.\" binaries using the old libc5 struct will corrupt
.\" .IR /var/run/utmp " and/or " /var/log/wtmp .
.\" .SH BUGS
.\" This man page is based on the libc5 one, things may work differently now.
.SH SEE ALSO
.BR ac (1),
.BR date (1),
.BR init (1),
.BR last (1),
.BR login (1),
.BR logname (1),
.BR lslogins (1),
.BR users (1),
.BR utmpdump (1),
.BR who (1),
.BR getutent (3),
.BR getutmp (3),
.BR login (3),
.BR logout (3),
.BR logwtmp (3),
.BR updwtmp (3)
|