LASTLOG(8)

๐Ÿ’– LASTLOG(8) ๐Ÿ’–

okay bestie, gather round, because this one is literally the receipts of who logged in last. it's lastlog, it lives in the System Management Commands corner of the manual, and it is lowkey iconic.


โœจ NAME โœจ

lastlog โ€” reports the most recent login of all users or of a given user ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

lastlog [options]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so what does she actually do? lastlog formats and prints the contents of the last login log โ€” that's the /var/log/lastlog file, no cap. the login-name, the port, and the last login time all get printed. ๐ŸŽ€

the default (like, zero flags, just vibes) causes lastlog entries to be printed, sorted by their order in /etc/passwd. periodt.


๐Ÿ’… OPTIONS ๐Ÿ’…

these are the options that apply to the lastlog command, and yes we're going through every single one:

  • -b, --before DAYS โ€” print only lastlog records older than DAYS. it's giving "show me the ancients". ๐Ÿ’€
  • -C, --clear โ€” clear lastlog record of a user. bestie, this option can be used only together with -u (--user)). don't try it solo, she will not cooperate.
  • -h, --help โ€” display help message and exit. the classic "help me please" move. ๐Ÿ™ˆ
  • -R, --root CHROOT_DIR โ€” apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. only absolute paths are supported, so no shortcuts bestie. ๐Ÿšซ
  • -S, --set โ€” set lastlog record of a user to the current time. this one can be used only together with -u (--user)). same rule as -C, she's not a solo act. โœจ
  • -t, --time DAYS โ€” print the lastlog records more recent than DAYS. main character energy only. ๐Ÿ‘‘
  • -u, --user LOGIN|RANGE โ€” print the lastlog record of the specified user(s).

the users can be specified by a login name, a numerical user ID, or a RANGE of users. and this RANGE of users can be specified with a min and max values (UID_MIN-UID_MAX), a max value (-UID_MAX), or a min value (UID_MIN-). pick your fighter. ๐ŸŒˆ

if the user has never logged in, the message ** Never logged in** will be displayed instead of the port and time. ghosted by your own login history fr fr. ๐Ÿ˜ญ

only the entries for the current users of the system will be displayed. other entries may exist for users that were deleted previously โ€” so yeah, there's lore in there. ๐Ÿ’€


๐Ÿ“ NOTE ๐Ÿ“

the lastlog file is a database which contains info on the last login of each user. you should not rotate it. do not. nope. ๐Ÿ›‘

it's a sparse file, so its size on the disk is usually much smaller than the one shown by ls -l โ€” which can indicate a really big file if you have in passwd users with a high UID. the way that number lies to you is honestly rude. ๐Ÿ™ˆ

you can display its real size with ls -s. use that one instead, iykyk. ๐Ÿ’–


โš™๏ธ CONFIGURATION โš™๏ธ

the following configuration variables in /etc/login.defs change the behavior of this tool:

LASTLOG_UID_MAX (number) ๐ŸŽ€

highest user ID number for which the lastlog entries should be updated. as higher user IDs are usually tracked by remote user identity and authentication services, there is no need to create a huge sparse lastlog file for them. like, why would you. ๐ŸŒธ

no LASTLOG_UID_MAX option present in the configuration means that there is no user ID limit for writing lastlog entries.


๐Ÿ“‚ FILES ๐Ÿ“‚

  • /var/log/lastlog โ€” database times of previous user logins. this is the file, the whole plot. ๐ŸŒŸ

โš ๏ธ CAVEATS โš ๏ธ

large gaps in UID numbers will cause the lastlog program to run longer with no output to the screen โ€” i.e. if in lastlog database there is no entries for users with UID between 170 and 800, lastlog will appear to hang as it processes entries with UIDs 171-799. it's not frozen bestie, she's just going through it. ๐Ÿซ 

having high UIDs can create problems when handling the /var/log/lastlog with external tools. although the actual file is sparse and does not use too much space, certain applications are not designed to identify sparse files by default and may require a specific option to handle them. so like, read the docs before you blame the file. ๐Ÿ’œ


ok that's the whole page, every option, every number, every caveat, nothing skipped, we ate and left no crumbs ๐Ÿ’…โœจ

this lil masterpiece is from shadow-utils 4.13, dated 05/30/2024 โ€” and LASTLOG(8) said what she said. bye bestie, go check your login history ๐Ÿฆ‹๐ŸŽ€๐Ÿ’–

๐Ÿ“ฆ where this page comes from