Managing Local Linux User Accounts

In guide I will be showing you how to manage local user accounts ranging from creation to modification including things such as adding to sudoers list and changing passwords. You will need root permissions so for convenience sake we will just switch to root using “sudo su”.

Creating A User Account

You can create a user account by using the useradd command. There are plenty of options you can specify while creating a user, for a full list you can simply run useradd by itself as shown below. Please note that your new user will be unable to login until you set a password using the second command.

useradd command

In the below example I will create a standard local user named mikey.

You can verify the user was created successfully by running the two following commands.

Add user in linux

Modifying A User Account

You can modify a user account after you created it by using the usermod command. You can change a variety of things with this command ranging from their default shell to their “full name”. For a full list of options simply run the command usermod by itself. In the example below I will change the users actual name (not login name) to Michael.

Modify User Linux

Modifying A User Password

To change a local user’s password all you will need to do is run the passwd command as root. Below is an example of how to change the password for the account I created during this tutorial.

Modify User Linux

Disabling A User Account

To disable a user account without removing it or in other words prevent them from logging in, all you need to do is run the passwd command with -l. What it does is basically add a ! in-front of the user’s password hash in the shadow file. To reverse it change -l to -u.

Lock Linux User Account

Granting/Revoking A User Sudo Permissions

To add a user to the sudoers list which will give them permission to run commands under root privileges as-well as login as root (sudo su), you simply have to add them to the sudo user group with the following command. If they are currently logged in when you run this, they will need to re-login. This is also how you add or remove a user from any other group that you may want them to be part of.

Grant User Sudo Permissions

Removing A User Account

If you want to remove a user then the userdel command will do this for you. You have the option of removing the user but keeping their home directory and the files within it or removing them as-well (you may get a similar error to the one shown but that is ok). Below is an example of how to do both options.

Remove User In Linux

I hope this tutorial has helped you learn how to work with user accounts. Please don’t forget to like, comment, or share!

Leave a Reply

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