The article illustrates how to create user accounts via GUI and CLI in Manjaro Linux. We also describe predefined user account settings and files to configure the user environment. Lastly, we describe CLI tools usermod and userdel to modify account settings and delete the account.
Getting Started
Every user of a specific Manjaro system must have a separate user account. It provides a secure area for each user to store files and offers user interface customization of a path, GUI, environment, shell, etc. Manjaro allows adding user accounts in several ways, that is, via GUI/CLI. We will discuss both of them with their pros and cons.
Create User Account via GUI
Go to the Manjaro Settings Manager and click User Account.
The User Account window will show current user accounts with the options plus ‘+’ and minus ‘-‘ at the bottom left corner to add or remove new/old accounts.
To add a new account, click on the ‘+’ sign. A prompt appears to add new user credentials. Click on create to save changes.
A window prompt for root to authenticate and apply changes.
The deletion of a user account involves a simple step of highlighting the about to be removed user account and clicking the minus ‘-‘ sign. However, it only helps get rid of the user and not the data belonging to the user, which is a security loophole.
Create User Account via CLI
Even though GUI is a lot more convenient for beginner users to create/delete user accounts. But sometimes, it’s a lot more convenient to add multiple user accounts via shell scripts and include/exclude unavailable features from the Manjaro Settings Manager.
For this purpose, CLI commands are available to add and manage user accounts. The simplest way of creating a new user is with the useradd command. Open the terminal and use the useradd command with superuser privileges to create a user with a login name.
The command also allows to include account details with various parameters. Some of the options available are:
- c: provides new user account description
- -d: allows to set users home directory
- -e: it sets the expiration date of the account in YYYY-MM-DD format
- -g: sets a new user primary group. However, without the option, by default, a new primary group gets created with the username.
- -s: option sets command shell to be used by the user.
- -G: add the user to a set of comma-separated groups
For instance, the following useradd command uses some of the above-listed parameters. In this command, the useradd tool adds jake in the user, primary group, and add (-G) to mysql and apache groups. Lastly, it assigns zsh as the default command-line shell (-s).
In creating the above account, the useradd command further takes several actions:
- It reads /etc/login.defs and /etc/default/useradd to use default values.
- Checks for the included parameters to override default values.
- Create user entry in /etc/passwd and /etc/shadow files. For instance, the above command adds the following line in the /etc/passwd file to represent the jake account.
- Creates new group entries in the /etc/group file. The above output shows useradd assigns 1001 as the user ID and 1011 as group ID that represents jake ID in the /etc/group file.
- It also creates a home directory /home under the user’s name /home/jake.
- Copies files in the /etc/skel directories to the new user directories.
jake:x:1001:1011:Jake Stan:/home/jake:/bin/zsh
Jake:x:1001:
Default Settings
The command determines the default values from /etc/login.defs and /etc/default/useradd files. Open the /etc/login.defs file in the text editor to change the default settings:
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
UID_MIN 1000
UID_MAX 60000
GID_MIN 1000
GID_MAX 60000
CREATE_HOME yes
For instance, the PASS_MAX_DAYS and PASS_MIN_DAYS represent max/min days assigned to use the set password, where PASS_MIN_LEN sets the minimum length of the assigned password. Other variables enable the customization of a range of numbers to assign user and group IDs. To only view the default settings, use the useradd -D command.
Modify User Accounts
Manjaro provides a usermod command to modify current user account settings. It offers parameters that mirror the options available with the useradd command. For instance, the following command changes the current user shell environment to /bin/csh.
Similarly, use the following command to add user jake to another list of groups. The use of an -a option with -G ensures that new supplementary groups are included in the user’s old groups.
Remove User Accounts
Like any other distribution, Manjaro Linux also provides userdel commands to delete the user accounts. Delete the user name account as follows.
However, the above command doesn’t delete the user jake’s home directory. Include an -r option to delete the home directory as well.
The above command doesn’t remove all the files associated with the jake account, except for the files deleted with the -r option. Such that all the files are available with the previous user’s user ID number.
Before account deletion, check all the files belonging to the user account via the find command. After deletion, use the find command again to search all files with the given user ID number and assign them to another user as it’s a security risk.
manjaro@manjaro:~$ find / -uid 1001 -ls
Here’s another way to find files not associated with any account.
Conclusion
The article details the process of creating, modifying, and removing user accounts via a command-line interface. We demonstrate various parameters available as the command options to overwrite the default user account settings. The article also shows a simple way to create a user account from GUI. User account creation/modification or management is the day-to-day task of a system administrator. Similarly, it’s important to remove the user files after their account deletion securely. The article is a one-stop guide for understanding the basics of user account management.