10 Linux User Management Commands

10 Linux User Management Commands

Estimated reading time: 4 minutes

I’ve worked with both GUIs and command-line interfaces, and I can confidently say that command-line commands are my go-to. They’re efficient, precise, and reliable—especially if you’re working on remote servers where a GUI isn’t even an option. In this guide, I’ll cover 10 important Linux user management commands that every admin should know, from adding users to locking accounts.

Why Linux User Management Commands Are Essential

Knowing your way around user management is key, whether you’re a sysadmin at a large company or managing a personal server. Proper user management helps ensure that each user has the right level of access and that unused accounts are dealt with securely. I’ve selected these Linux user management commands based on several years of experience—they cover the basics and a little extra.

1. Adding Users with adduser

Creating a new user on Linux is straightforward with the adduser command. Unlike useradd, this command sets up the home directory and prompts you for a password without extra options.

Replace USERNAME with the name you want for the user. You’ll be prompted to enter additional information, like the user’s full name, and to set a password.

More on adduser on Linux

2. Modifying Users with usermod

If you need to update a user’s access, like adding them to a group or changing their home directory, usermod has you covered. For example, you can add a user to a new group:

In this example, GROUP is the group name, and USER is the username. Need to lock an account temporarily? Just use:

And to unlock, it’s as simple as switching -L to -U.

3. Changing Passwords with passwd

Passwords need changing, and sometimes users need a prompt. With the passwd command, I can quickly update or expire a user’s password, prompting them to create a new one.

To expire a user’s password and force a reset, use:

This command is handy for enforcing regular password changes across your server environment.

4. Deleting Users with userdel

You don’t want that account left open when a user no longer needs access. The userdel command deletes the account and can also remove their home directory.

The -r option ensures the user’s home directory is deleted, keeping your system tidy.

5. Viewing User Details with lslogins

Want to check the last login time, IP address, or groups for a specific user? lslogins is a quick way to gather all this info.

With this command, you can keep tabs on user activity, which can be useful for monitoring and security.

6. Checking Group Membership with groups

Knowing a user’s group memberships helps understand their permissions. The groups command lists all groups associated with a user.

With this, you can easily verify and manage group-based access on your system.

7. Identifying User Details with id

The id command is a fast way to get all identification details for an user, including UID, GID, and group memberships. It’s a go-to for troubleshooting permissions.

Running this gives you a snapshot of the user’s identity on the system.

8. Switching Accounts with su

Sometimes, you need to switch from your account to another without logging out. The su command does just that, allowing you to access another user’s environment directly.

This command is especially handy when testing permissions or running commands as a different user.

9. Checking Active Users with who

Want to know who’s currently logged in? The who command provides this information, along with login times and terminals.

Monitoring active sessions becomes easier with who, as it shows you exactly who’s online and active.

10. Viewing Login History with last

Lastly, for a deeper look at user activity, last shows a history of logins, complete with login times and IP addresses.

This is great for tracking user behavior and ensuring there’s no unauthorized access to your system.

Conclusion

Using these Linux user management commands, you can easily manage user access, ensuring the right people have access while keeping your systems secure. Linux is a powerful platform, and with these commands, you’ll have the means to manage users easily!

Further Reading

Leave a Reply

Your email address will not be published. Required fields are marked *