Users in Linux
by Felix Kinaro About 2 min reading time
Users are people or programs that run sessions on a Linux box. The distinction of who or what owns a process or file enables granular management of access rights.
The Root User
This is the administrative user who has unlimited privileges on the system. They can create, modify or delete files, enable or disable devices and start or stop system processes.
With this unlimited power is the caveat for potentially doing irreversible damage. For instance, if the root user were to delete
/usr/bin then all installed programs would be gone.
It is a wise move to set shell aliases for commands that can be destructive whenever you are working as the root user. We can set an alias for
rm as follows:
alias rm="rm -iv"
With this in place, the
rm command will log all output and prompt before executing a deletion.
We can add our aliases to
.zshrc files depending on the current login shell. Then run
source ~/.zshrc to load the changes.
Adding a New User
There are two programs for adding users: useradd and adduser.
useradd is the natively compiled binary, whereas adduser is a Perl script wrapper for useradd.
adduser creates a new user with the home directory set and other features as you would expect. It has an interactive experience by prompting for details.
With useradd, you have to specify all the details for the new user. It is recommended that you user the
adduser command when creating users.
Changing a User's Group
Example: Add Our User to the sudo Group
To grant our user administrative privileges on our system, we need to run:
usermod -a -G sudo kinaro
Our user can now perform tasks that require root-level privileges like installing and removing packages. To run a command as root run
Groups are not limited to sudo alone. We can add our user to the
www-data group so that they can modify web server files with ease.
Removing a User
We can remove a user with the
To remove our newly created user and his home directory, we use:
userdel kinaro --remove
--remove parameter specifies that we want to delete all files associated with the user. Files that are outside the home directory will not be removed.
We have explored the basics of creating users and managing their groups.
To read more on the commands used, type
man command into the terminal to view the possible ways you can use the command.