{"id":843,"date":"2024-01-01T02:53:28","date_gmt":"2024-01-01T05:53:28","guid":{"rendered":"https:\/\/freeshell.de\/~felipe\/blog\/?p=843"},"modified":"2024-06-09T15:43:46","modified_gmt":"2024-06-09T18:43:46","slug":"how-to-add-a-user-on-arch-linux","status":"publish","type":"post","link":"https:\/\/freeshell.de\/~felipe\/blog\/01\/2024\/linux\/how-to-add-a-user-on-arch-linux\/","title":{"rendered":"How to Add a User on Arch Linux"},"content":{"rendered":"\n<p>User management is the most needed utility in any operating system because it makes your system secure and provides you an opportunity to assign the right privileges to the right ones. The users can make a lot of changes to your system according to the rights they have. Therefore, it\u2019s very necessary to have a very close look at each activity that is performed by the users. Thus, this guide elaborates on the method to add the new users to the Arch Linux system and how to manage them. Before moving towards the addition of users in the Arch Linux system, we need to make sure that the group is already enabled. To do so, we use the following \u201cvisudo\u201d command with \u201csudo\u201d. This is typically used to make changes to the sudoers file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0EDITOR=nano\u00a0visudo<\/code><\/pre>\n\n\n\n<p>The sudouers file is launched in the \u201cnano\u201d editor. You will find the \u201cwheel\u201d group in the following illustration. Uncomment it and save the file to update the changes. Use \u201cCtrl-x\u201d to exit.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/freeshell.de\/~felipe\/blog\/wp-content\/2024\/01\/word-image-41442-1.webp\"><img fetchpriority=\"high\" decoding=\"async\" width=\"778\" height=\"502\" src=\"https:\/\/freeshell.de\/~felipe\/blog\/wp-content\/2024\/01\/word-image-41442-1.webp\" alt=\"\" class=\"wp-image-846\" srcset=\"https:\/\/freeshell.de\/~felipe\/blog\/wp-content\/2024\/01\/word-image-41442-1.webp 778w, https:\/\/freeshell.de\/~felipe\/blog\/wp-content\/2024\/01\/word-image-41442-1-300x194.webp 300w, https:\/\/freeshell.de\/~felipe\/blog\/wp-content\/2024\/01\/word-image-41442-1-768x496.webp 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Add a User<\/strong><\/h2>\n\n\n\n<p>Now, we add a new \u201ctest\u201d user to the Arch Linux system using the \u201cuseradd\u201d instruction with the \u201csudo\u201d rights. This instruction doesn\u2019t take anything in return which indicates that the user is created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0useradd\u00a0test<\/code><\/pre>\n\n\n\n<p>Now, it\u2019s very necessary to secure an account that is just created. For this, we establish a&nbsp;new user and add a new password. Therefore, we utilize the shell\u2019s \u201cpasswd\u201d command along with the user \u201ctest\u201d as our input. You are prompted by the terminal to enter a new password. After providing the password twice, it is updated successfully.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0passwd\u00a0test<\/code><\/pre>\n\n\n\n<p>New password:<\/p>\n\n\n\n<p>Retype new password:<\/p>\n\n\n\n<p>passwd: password updated successfully<\/p>\n\n\n\n<p>In case you want to perform the process of user addition to arch Linux along with setting its password at once, you can do so by modifying the useradd instruction. For this, you should use the \u201c-m\u201d and \u201c-p\u201d flags in the instruction. The \u201c-m\u201d flag can be utilized to name a new user while the \u201c-p\u201d option can be used to set the password for the user to be created. For example, we create a \u201cdummy\u201d user with the \u201cdummy123\u201d password via the useradd instruction in the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0useradd\u00a0-m\u00a0dummy\u00a0-p\u00a0dummy123<\/code><\/pre>\n\n\n\n<p>The other thing that you can achieve using the useradd instruction is to set the custom directory for a new user using the \u201c-d\u201d option with the path to the directory. The following instruction shows that we created a \u201cnew\u201d user and a \u201cnew\u201d password and set its custom directory as \u201c\/tmp\/new\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0useradd\u00a0-d\u00a0\/tmp\/new\u00a0-m\u00a0new\u00a0-p\u00a0new<\/code><\/pre>\n\n\n\n<p>There are a lot of groups which are available in Arch Linux to perform the different functions according to their group types. To add a user to a particular group in Arch Linux, the useradd command comes up with the \u201c-G\u201d option to add a particular user to any group. For example, the following instruction adds a new \u201cblue\u201d user in the wheel, audio, and video group while creating:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0useradd\u00a0-G\u00a0wheel,audio,video\u00a0-m\u00a0blue\u00a0-p\u00a0blue<\/code><\/pre>\n\n\n\n<p>There is also a way to add the system users in Arch Linux using the useradd instruction. For this, you need to use the \u201c-r\u201d option with the \u201c-s\u201d flag followed by the path to the \u201cfish\u201d directory, i.e. \u201c\/usr\/bin\/fish\u201d. The \u201chell\u201d user is created as you can see from the attached command. The output of this instruction generates a warning.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0useradd\u00a0-r\u00a0-s\u00a0\/usr\/bin\/fish hell<\/code><\/pre>\n\n\n\n<p>useradd: Warning: missing or non-executable shell \u2018\/usr\/bin\/fish\u2019<\/p>\n\n\n\n<p>You can also do it if you wish to confirm the outcome of the aforementioned instruction. For that, try using the following \u201csu\u2019 instruction with the name of a user that you just created. It might show you a warning.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0su\u00a0- hell<\/code><\/pre>\n\n\n\n<p>su: warning: cannot change directory to \/home\/hell: No such file or directory<\/p>\n\n\n\n<p>After that, try the whoami one-word instruction on the shell. You will see that it returns the name of a system user that you just created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ]$\u00a0whoami<br \/>hell<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>User Modification<\/strong><\/h2>\n\n\n\n<p>While using the arch Linux and creating new users, you should have a piece of knowledge about the user properties and a way to modify them. Consider the scenario where we want to rename the \u201ctest\u201d to \u201ctest1\u201d user. For this, we use the usermod instruction with the \u201c-l\u201d option followed by the new name and then an old name as shown in the following attached command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0sudo\u00a0usermod\u00a0-l\u00a0test1\u00a0test<\/code><\/pre>\n\n\n\n<p>Now, if you want to set the expiry date for a newly created user account, you can also set that using the usermod instruction followed by its \u201c\u2014expiry date\u201d option. The option follows the date and then a username. The \u201ctest1\u201d is our new user name in this case.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0sudo\u00a0usermod\u00a0--expiredate\u00a02022-01-23\u00a0test1<\/code><\/pre>\n\n\n\n<p>Now, if you want to add your user to the additional groups, you can do so by using the \u2013append option in the usermod instruction followed by the \u2013groups option with the group names and the name of a user to be added. The wheel and users are 2 groups while the test1 is a user.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0usermod\u00a0--append\u00a0--groups\u00a0wheel,users\u00a0test1<\/code><\/pre>\n\n\n\n<p>To modify the default shell that is used by a user, you can use the \u2013shell option in a usermod instruction. In this instruction, you should provide the path to the shell file like \/usr\/bin\/bash.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0sudo\u00a0usermod\u00a0--shell\u00a0\/usr\/bin\/bash\u00a0test1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Lock\/Unlock the User<\/strong><\/h2>\n\n\n\n<p>In case you don\u2019t want anybody to use the particular account, you might lock it. To lock an account, the \u2013lock option can be used in the usermod instruction with the name of a user which is \u201ctest1\u201d.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host ~]$\u00a0sudo\u00a0usermod\u00a0--lock\u00a0test1<\/code><\/pre>\n\n\n\n<p>In the same way, if you want to allow a particular user to use its system account, you should unlock the particular account using the \u201cunlock\u201d option in the usermod instruction with the same user name as shown in the attached instruction:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0sudo\u00a0usermod\u00a0--unlock\u00a0test1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Delete the User<\/strong><\/h2>\n\n\n\n<p>To display the currently available users of your Arch Linux, try using the instruction as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0cut\u00a0-d:\u00a0-f1\u00a0\/etc\/passwd<br \/>root<br \/>bin<br \/>daemon<br \/>omar<br \/>dummy<br \/>new<br \/>blue<br \/>hell<br \/>test1<\/code><\/pre>\n\n\n\n<p>To delete the new and previously made users, the \u201cuserdel\u201d instruction can be utilized. This command takes one or more usernames at once.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user@host  ~]$\u00a0sudo\u00a0userdel test1<br \/>&#91;user@host  ~]$\u00a0sudo\u00a0userdel hell<br \/>&#91;user@host  ~]$\u00a0sudo\u00a0userdel blue new<br \/>&#91;\/c]c<br \/>If you create a user with a related home directory, you can delete it using the \u2013r option.<br \/>&#91;cc\u00a0lang=\"bash\"\u00a0width=\"100%\"\u00a0height=\"100%\"\u00a0escaped=\"true\"\u00a0theme=\"blackboard\"\u00a0nowrap=\"0\"]<br \/>&#91;omar@omar ~]$\u00a0sudo\u00a0userdel\u00a0-r\u00a0dummy<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The introductory paragraph explains the importance of user management in all sorts of operating systems. To support the discussion, we tried the different instructions to create the new users, modify, lock or unlock, and delete them. For this, we utilized the useradd, usermod, and userdel instructions with the \u2013m, -p, -G, -r, -s, -l, \u2013append, \u2013shell, \u2013lock, \u2013unlock, and \u2013expiredate options.<\/p>\n\n\n\n<p>Article originally written by https:\/\/linuxhint.com\/add_users_arch_linux\/<\/p>\n\n\n\n<p><strong>NOTES: <\/strong><\/p>\n\n\n\n<p>You have to use&nbsp;<code>-m<\/code>, otherwise no home directory will be created. If you want to specify the path of the home directory, use&nbsp;<code>-d<\/code>&nbsp;and specify the path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>useradd -m -d \/PATH\/TO\/FOLDER USERNAME\n<\/code><\/pre>\n\n\n\n<p>You can then set the password with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>passwd USERNAME\n<\/code><\/pre>\n\n\n\n<p>All of the above need to be run as root, or with the&nbsp;<code>sudo<\/code>&nbsp;command beforehand. For more info, run&nbsp;<code>man adduser<\/code>.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>User management is the most needed utility in any operating system because it makes your system secure and provides you an opportunity to assign the right privileges to the right ones. The users can make a lot of changes to your system according to the rights they have. Therefore, it\u2019s very necessary to have a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,70],"tags":[102,66,103,67,101],"class_list":["post-843","post","type-post","status-publish","format-standard","hentry","category-arch","category-linux","tag-adduser","tag-arch","tag-deluser","tag-linux","tag-user-management"],"_links":{"self":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/comments?post=843"}],"version-history":[{"count":6,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"predecessor-version":[{"id":867,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/843\/revisions\/867"}],"wp:attachment":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/tags?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}