User commands and logs
Keeping Log
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.
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.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.