That’s why account management is one of the major parts of being a system admin. There are so many crucial parts involved in the management that even the slightest mistake can cost the entire system taken over by unwanted intruder(s).
Today, let’s check out on adding user account(s) on Arch Linux.
User accounts
A user is anyone who uses a computer. In the case of Linux users, it indicates the names that represent those users. While Linux allows a robust system for multiple user access at the same time, security is a big concern. Without proper permission control, the system can become vulnerable to all sorts of misuse.
For making the management easier, all the user accounts in a Linux system are separated into different groups. The groups are the actual definition of the users’ power over the system. There are some default groups that are usually more than enough to handle the job. However, in the case of an enterprise-level system, more groups may be necessary. That’s up to the system admins to decide whether more groups are needed or not.
In this guide, we’ll be covering how to add, remove and manipulate various factors of a user account on Arch Linux.
Note: If you’re testing on your home computer, feel free to wander around. However, if these actions are to be performed on a corporate or enterprise-level system, I strongly recommend exercising extreme caution. These actions are better performed by a sophisticated system admin rather than average Joes.
User account actions
There is a multitude of actions for managing the user accounts. The best way to do them is through the terminal. It allows greater control and understanding. Fear not; if you’re willing to pay a bit more attention, it’s nothing so special.
Enabling the “wheel” group
This is the very first important step. Without enabling the wheel group, adding admin account to the system is not possible.
We need to modify the “sudoers” file. Run the following command.
This will launch the “/etc/sudoers” file with Nano editor. Now, scroll down and uncomment the “wheel” group.
Save the file by pressing “Ctrl + O” and exit the editor by pressing “Ctrl + X”.
The wheel group enables creating a user with the ability to run commands as “root”. Root holds the ultimate power of the entire system and if you’re using Linux for quite some time, you already know the importance of running multitudes of maintenance and tweaks that require root access.
Adding a user
Now, we’re ready to add a new user. The “useradd” command follows the following structure.
Adding a new user in the system is quite simple. Just tell “useradd” the username.
Unfortunately, this command will lock the user without any way of logging in. The user would also have no home directory. To alleviate the problem, use the following command structure.
This will create a unique home directory for the user and let the new account to be accessible. Now, assign a login password for the newly created user.
Note: This command can also be used for updating the password of an existing account as well.
It’s possible to squeeze all the aforementioned steps in one single line.
“useradd” is also capable of setting a custom directory for the newly created user. For that purpose, use the “-d” flag.
“useradd” is also capable of performing a lot of other functions. For example, the “-G” flag to define which group to register for.
-p <password>
If you need to add a system user, use the following strucutre.
Need to verify the result? Try logging into the user account with the following command.
sudo whoami
Modifying user attributes
It’s also important to know how to change the user attributes. In cases, a user might need changes in the permission and other attributes. For that purpose, we need the usermod tool. It’s capable of altering a lot of attributes.
sudo usermod <options> <username>
For example, you can change the login name of a user!
Need to change the home directory for the user? Use the “-d” or “–home” flag.
You can also set the expiry date of a user! After the time, the user will no longer be available on the system.
If a user needs to be registered in additional groups, use the “–append” and “–groups” flags together. When listing the groups, there must not be any space between the commas.
Change the default shell of an user using the “–shell” flag.
Like useradd, usermod also allows stacking all the parameters in one single line.
–shell <shell_path>
If, for some reason, a user needs to be locked down, usermod can do the job.
The user can be enabled using the following command.
Deleting a user
It’s the final part of this guide. In the lifecycle, a system will have new users and in cases, old users will get removed/updated. For removing users, userdel is a dedicated tool.
Use the following command for removing a user.
If you want to remove the user with associated home directory, use the following command.
Final thoughts
These are just simple usage cases for all the methods mentioned before. There are plenty of other ways where these commands can offer a real solution.
For deeper and advanced usage of these commands, consult their man pages. There are all the available options you can use to use in the appropriate situations. Feel free to roam around and have a better understanding.