Linux Stall
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials
No Result
View All Result
Linux Stall
No Result
View All Result
Home How to

How to Create Update Lock & Remove Linux User Accounts

Chankey Pathak by Chankey Pathak
July 11, 2020
in How to
45 0
0
Character illustration of people holding user account icons
15
SHARES
750
VIEWS
Share on FacebookShare on Twitter

In this 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. Please note that your new user will be unable to login until you set a password using the second command.

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

useradd -c "mikey" -d "/home/mikey" -m -s "/bin/bash" mikey # Create the user
passwd mikey # Set a password for the user

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

grep mikey /etc/passwd
ls -l /home | grep mikey

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.

usermod mikey -c "Michael" # Apply changes
grep mikey /etc/passwd # Verify changes

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.

passwd mikey

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.

passwd mikey -l # Lock this account
passwd mikey -u # Unlock this 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.

adduser mikey sudo # Add user to sudo group
deluser mikey sudo # Remove user from sudo group

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.

userdel -r mikey # Remove user and home directory
userdel mikey # Remove user but keep home directory

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

Tags: how tousers management
Previous Post

Protect Your SSH From Bruteforce With Fail2Ban

Next Post

Creating Bash Loops With Examples

Chankey Pathak

Chankey Pathak

Data Scientist at Morgan Stanley. I've been using Linux since past 12 years. I plan to share what I know about Linux in this blog.

Related Posts

The three-dimensional network topology infographics with ip addresses 3d illustration
How to

Identifying and Resolving IP Address Conflicts with Linux

July 23, 2020
procmon
How to

Microsoft releases ProcMon (Process Monitor) utility for Linux

July 21, 2020
searching file
How to

How to find files by size in Linux

July 12, 2020
Blue padlock icon computer security system vector
How to

How To Enable TLS Encryption On Postfix

July 12, 2020
Blue padlock icon computer security system Encryption
How to

Running Commands Automatically Over SSH

July 12, 2020
sar command output
How to

How to Install And Enable SAR (SYSSTAT) On Linux Servers

July 12, 2020
Next Post
A programmer coding

Creating Bash Loops With Examples

Leave a Reply Cancel reply

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

  • Terms and Conditions
  • Contact Us
  • About Us

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

No Result
View All Result
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In