useraddcommand allows admins to create new users, while
userdel(as you can imagine) allows us to delete existing users. Let’s look a few examples of this below:
Using USERADD to Create Users
useradd command is used to create new users or update user information such as setting a user’s home directory, password, and other settings. Let’s create a new user:
sudo useradd linuxman
useraddis to also pass the
-moption which will automatically create the new user’s home too and set the permissions on that dir correctly.
sudo useradd -m linuxman
useraddbut it also wack as the password can be seen by anyone listing the processes. Instead we will use
sudo passwd linuxman New password: Retype new password: passwd: password updated successfully
passwdwill prompt you to enter a password for the given user, note that the terminal will not show your password nor the amount of characters as a security measure, thus double check you’ve typed your password correctly.
Adding users to groups
To add your user to existing groups on the system we would use the
-G option and specify what group you want to add the user to during user creation. Here we are creating a user and adding them to the group “wheel” (or
sudo useradd -m -G wheel linuxman
usermod, but that is beyond the scope of this post.
Changing the defaults
All the above examples are good for single or infrequent uses, but if you find yourself constantly having to make new users or some other unique circumstance, we can edit this file
/etc/login.defs. This file will have a ton of options that modify the default
#/etc/login.defs ... # If useradd(8) should create home directories for users by default (non # system users only). # This option is overridden with the -M or -m flags on the useradd(8) # command-line. # #CREATE_HOME yes ...
The option we are looking for is called
#CREATE_HOME which will be commented out, simply remove the # and any user made after this edit will have their home directory created without having to pass
Using USERDEL to Delete Users
userdelcommand along with the username you want to remove:
sudo userdel linuxman
-r, then that users’s home directory won’t be removed. The complete command will look like this:
sudo userdel linuxman -r
userdelto your terminal know-how will make administrating any system a breeze as you’ll be able to add/remove users without much fuss. As always It is important to remember to proceed with caution when it comes to user management, as you can very easily wreak havoc on a system. Thanks for reading!