User commands and logs
Keeping Log
![](/var/linux_magazin/storage/images/linux-magazine.com/issues/2013/152/command-line-logging-tools/78002279_20.png/582249-1-eng-US/78002279_20.png1_medium.png)
Many logging and user-related commands can help you check on your system and keep track of security matters. We guide you through several helpful tools.
You can tell that Unix and Linux were designed for multiple logins by all the logs and commands that provide information about users. These tools often detect the first signs of an attempt to break into your system. In an institutional environment, they can be used to check not only what resources are being used but also whether users are doing what they are supposed to be doing.
If you have done any systems administration at all, you have probably used the adduser
command. The adduser
command (Figure 1) provides a simple wizard to help you create a new account. By default, much of the work is done for you, such as automatically creating a user ID (UID). However, you can choose to specify many details for yourself with options like --gid ID
and --shell SHELL
.
Or, you might have used useradd
instead, which is less convenient for creating a new user than adduser
but can be used for editing the details of an already existing user. Both of these commands have counterparts in deluser
and userdel
, which are similar in function, but whose options are different. For example, userdel
has a -f
or --force
option that deluser
lacks. And, userdel
uses -r
or --remove
to delete the user's home directory and mail and printing spools instead of deluser
's --remove-home
and automatic removal of an account's spools.
But, these are just some of the items in the basic toolkit for users and their groups. At least 10 other logs and commands present information for administrator views – some of them overlap in functionality, but all provide detailed information.
User Information in Logs
Linux stores vast quantities of information about every aspect of the system, and users are no exception. Many logs are kept in plaintext files and are viewable with commands like less
or cat
. However, many are also long, so, when you are trying to pinpoint problems, you are usually better off using the command tail -p LOGFILE
. This command displays only the last dozen lines or so of the file, which are slowly replaced as new system messages are generated.
Other logs are stored in databases, so they are best viewed using the command that has the same name as the file.
lastlog
The /var/log/lastlog
file is a database that records the previous logins of users. Entered by itself, the lastlog
command gives a complete list of all users who are currently on the system, including system-created ones used by some daemons. Deleted users are not shown. For every user, it shows the port they are (or were) logged into and either the date of their last login or Never logged in – at least, not since the password was last changed.
However, the resulting list is long, so you'll probably want to modify it with |less
at the end of the command. Better yet, you can use -u
or --user
, followed by a login name to specify each user to include in the result by name or UID, or to specify a number of users by giving a range of UIDs with the start and end points separated by a hyphen (Figure 2).
Results can also be modified with -b DAYS
or --before DAYS
, which prints records that are older than the number of days entered. Alternatively, you can use -t DAYS
or --time DAYS
to view records that are more recent than the specified number of days.
faillog
The /var/log/faillog
database records the number of time that users have tried unsuccessfully to log in. The faillog
command makes two uses of the faillog database.
First, the faillog
command is used by the root user to check the number of times in which a specific user has failed to log in. This statistic is a possible sign of a partially cracked system or of a user whose account needs to be reenabled, because the system is set to disable users who make a certain number of successive login failures.
You can use either the -a
option to display information for all users or the options -u NAME
or -u UID
to specify a specific user (Figure 3). The results show the number of failed login attempts, followed by the maximum permitted on the system and the date and time of the last unsuccessful attempt. If a user has never had an unsuccessful login attempt, the date given is the earliest the CPU can display – for example: 12/31/69 16:00:00.
![](/var/linux_magazin/storage/images/linux-magazine.com/issues/2013/152/command-line-logging-tools/figure-3/582258-1-eng-US/Figure-31_large.png)
The second use of the faillog
command is to change how the system responds to failed logins. The options -m NUMBER
or --maximum NUMBER
set how many login failures can occur before an account is disabled; this is often set to 0 in most distributions, meaning that any number of login failures can occur. Additionally, the number of login failures for a specific account can be reset to 0 with -r
or --reset
.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.