{"id":2913,"date":"2018-02-19T17:33:18","date_gmt":"2018-02-19T14:33:18","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-adduser-addgroup-command\/"},"modified":"2018-02-19T17:33:18","modified_gmt":"2018-02-19T14:33:18","slug":"linux-adduser-addgroup-command-tutorial-for-beginners-7-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-adduser-addgroup-command-tutorial-for-beginners-7-examples\/","title":{"rendered":"Linux adduser\/addgroup Command Tutorial for Beginners (7 Examples)"},"content":{"rendered":"<p>As a Linux system administrator, one of the basic tasks that you&#8217;ll have to perform is to create accounts for new users and manage user groups. Of course, there are command line utilities that let you do this, and this tutorial, we will discuss the basics of two such commands: <strong>adduser<\/strong> and <strong>addgroup<\/strong>.<\/p>\n<p>Before we move ahead, it&#8217;s worth mentioning that all examples in this article have been tested on Ubuntu 16.04 LTS. Also, the article mainly discusses adduser, but addgroup also works in the same way for the most part.<\/p>\n<h2 id=\"linux-adduseraddgroup-commands\">Linux adduser\/addgroup commands<\/h2>\n<p>As the name suggests, these tools let you add new users and groups to the system. Here&#8217;s the basic syntax of these commands:<\/p>\n<p class=\"command\">adduser [options or flags] user<\/p>\n<p class=\"command\">addgroup [options or flags] group<\/p>\n<p>Following is how the man page describes these tools:<\/p>\n<pre> adduser\u00a0 and\u00a0 addgroup\u00a0 add users and groups to the system according to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 command\u00a0\u00a0\u00a0 line\u00a0\u00a0\u00a0 options\u00a0\u00a0\u00a0 and\u00a0\u00a0\u00a0 configuration\u00a0\u00a0\u00a0 information\u00a0\u00a0\u00a0 in<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/etc\/adduser.conf.\u00a0\u00a0 They\u00a0 are\u00a0 friendlier\u00a0 front ends to the low level<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tools like useradd, groupadd and usermod programs, by default\u00a0 choosing<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Debian\u00a0 policy conformant UID and GID values, creating a home directory<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 with skeletal configuration, running a custom script,\u00a0 and\u00a0 other\u00a0 fea?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tures.<\/pre>\n<p>The following Q&amp;A-styled examples should give you a good idea on how these utilities work.<\/p>\n<h2 id=\"q-how-to-use-adduser-and-addgroup-commands\">Q1. How to use adduser and addgroup commands?<\/h2>\n<p>Adding a user or group is fairly easy &#8211; all you have to do is to pass the name of the new user (or group) to the command. For example:<\/p>\n<p class=\"command\">adduser [user-name]<\/p>\n<p>Needless to say, you need to be root, or require escalated privileges for this process to work. The following screenshot shows a new user being added through this tool:<\/p>\n<p><a class=\"fancybox\" id=\"img-adduser-basic1\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/adduser-basic1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-adduser-addgroup-command-tutorial-for-beginners-7-examples.png\" alt=\"How to use adduser and addgroup commands\" width=\"467\" height=\"229\" title=\"\"><\/a><\/p>\n<p>So you can see, you&#8217;ll be asked a few questions, that you can choose to answer to press ENTER so that the system picks default values by itself.<\/p>\n<p><a class=\"fancybox\" id=\"img-adduser-basic2\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/adduser-basic2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-adduser-addgroup-command-tutorial-for-beginners-7-examples-1.png\" alt=\"Add a Linux user with adduser command\" width=\"458\" height=\"308\" title=\"\"><\/a><\/p>\n<p>Once added, you can switch to the new user using the su command in the following way:<\/p>\n<p><a class=\"fancybox\" id=\"img-adduser-basic3\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/adduser-basic3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-adduser-addgroup-command-tutorial-for-beginners-7-examples-2.png\" alt=\"Su command\" width=\"242\" height=\"56\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-adduseraddgroup-use-different-conf-file\">Q2. How to make adduser\/addgroup use different conf file?<\/h2>\n<p>As already mentioned in the beginning, by default, the adduser\/addgroup commands read the \/etc\/adduser.conf file to carry out their operations. However, if for some reason, you want them to read a custom file residing at a custom location, you can pass that information using the <em>&#8211;conf<\/em> option.<\/p>\n<p class=\"command\">adduser &#8211;conf [new-conf-file-name-path]<\/p>\n<h2 id=\"q-whats-the-difference-between-system-and-normal-usergroup\">Q3. What&#8217;s the difference between system and normal user\/group?<\/h2>\n<p>If you take a look at the man page documentation of these utilities, you will find that you can use adduser to add either a normal user or a system user.<\/p>\n<pre>Add a normal user<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If\u00a0 called\u00a0 with\u00a0 one\u00a0 non-option\u00a0 argument and without the --system or<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 --group options, adduser will add a normal user.<\/pre>\n<pre>Add a system user<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If called with one non-option argument and the --system option, adduser<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 will add a system user.<\/pre>\n<p>It&#8217;s important that you first know the difference between two.<\/p>\n<p>While technically there isn&#8217;t a difference between these users, you should create a system user when creating an account to run a system software like a daemon or a service &#8211; basically, if the account doesn&#8217;t require interactive usage. All in all, this\u00a0segregation helps keep user and software accounts separate.<\/p>\n<h2 id=\"q-how-to-prevent-a-user-from-logging-in\">Q4. How to prevent a user from logging in?<\/h2>\n<p>If you want to disable a user account, meaning preventing a user from logging in, use the <em>&#8211;disabled-login<\/em> option.<\/p>\n<p class=\"command\">adduser &#8211;disabled-login [OPTIONS] user<\/p>\n<p>This option sets the password to !, which means &#8220;login is deactivated, user will be unable to login.&#8221;<\/p>\n<p>Keep in mind that this will only prevent user login &#8211; you can still switch to this account from some other using the <em>su<\/em> command.<\/p>\n<h2 id=\"q-how-to-force-adduser-to-create-a-custom-home-directory\">Q5. How to force adduser to create a custom home directory?<\/h2>\n<p>As already discussed, the adduser command picks information from a configuration file, and this information includes directory to be used as user&#8217;s home directory. However, if you want, you can specify this yourself using the <em>&#8211;home<\/em> option.<\/p>\n<p class=\"command\">adduser &#8211;home [dire-name-path] user<\/p>\n<pre>--home DIR<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Use\u00a0 DIR\u00a0 as\u00a0 the user's home directory, rather than the default<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 specified by the configuration file.\u00a0 If the directory does\u00a0 not<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exist, it is created and skeleton files are copied.<\/pre>\n<p>There are other similar flags as well. For example, the <em>&#8211;no-create-home<\/em> option tells the tool to not create the home directory, even if it doesn&#8217;t exist. Then there&#8217;s <em>&#8211;shell<\/em> that you can use to force adduser to use a different shell as the user&#8217;s login shell, rather than the default specified by the configuration file.<\/p>\n<h2 id=\"q-how-to-create-user-or-group-with-custom-ids\">Q6. How to create user or group with custom IDs?<\/h2>\n<p>If you want, you can force adduser and addgroup to assign custom user and group IDs while creating a user and a group, respectively. This can be achieved using the <em>&#8211;uid<\/em> and <em>&#8211;gid<\/em> options.<\/p>\n<pre>--uid ID<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Force the new userid to be the given number.\u00a0 adduser will\u00a0 fail<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if the userid is already taken.<\/pre>\n<pre>--gid ID<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 When creating a group, this option forces the new groupid to\u00a0 be<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the\u00a0 given\u00a0 number.\u00a0\u00a0 When creating a user, this option will put<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the user in that group.<\/pre>\n<h2 id=\"q-how-to-make-adduseraddgroup-emit-minimal-or-maximum-information\">Q7. How to make adduser\/addgroup emit minimal or maximum information?<\/h2>\n<p>To make these tools emit minimum info, use the <em>&#8211;quiet<\/em> command line option. And in case you want these tools to be verbose, use the <em>&#8211;debug<\/em> option. The following screenshot gives a clear idea about the difference between the two:<\/p>\n<p><a class=\"fancybox\" id=\"img-adduser-quiet-verbose\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/adduser-quiet-verbose.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-adduser-addgroup-command-tutorial-for-beginners-7-examples-3.png\" alt=\"Adduser command verbosity\" width=\"500\" height=\"284\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Both adduser and addgroup commands have a decent learning curve, but that doesn&#8217;t mean they are hard to understand. In fact, you can begin with learning the options that help you do your work, and understand others gradually. We have already explained some of the options here. Once you are done with these, head to the common man page for these tools to learn more.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a Linux system administrator, one of the basic tasks that you&#8217;ll have to perform is to create accounts for new users and manage user groups. Of course, there are command line utilities that let you do this, and this tutorial, we will discuss the basics of two such commands: adduser and addgroup. Before we &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2913","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2913"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2913\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}