User commands and logs
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
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
userdel, which are similar in function, but whose options are different. For example,
userdel has a
--force option that
deluser lacks. And,
--remove to delete the user's home directory and mail and printing spools instead of
--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
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.
/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
--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.
/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.
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
Buy this article as PDF
A new study says it is possible to unmask 81% of TOR users.
Redmond joins the revolution by turning the .NET Core Runtime into a GitHub project.
Users only had 7 hours to update before the intrusions started.
It's official: The new web arrives
Kernel king admits his tone has alienated volunteers, but says the demands of the process require directness.
New flaw in an old encryption scheme leaves the experts scrambling to disable SSL 3
Lennart Poettering wants to change the way Linux developers talk to each other.
Enterprise giant frees itself from ink and home PCs (and visa versa).
Mozilla’s product think tank sinks silently into history.
TODO group will focus on open source tools in large-scale environments.