{"id":303,"date":"2009-04-16T22:37:43","date_gmt":"2009-04-16T15:37:43","guid":{"rendered":"http:\/\/adityo.blog.binusian.org\/?p=303"},"modified":"2009-04-16T22:56:21","modified_gmt":"2009-04-16T15:56:21","slug":"useradd-comand","status":"publish","type":"post","link":"https:\/\/adityo.blog.binusian.org\/?p=303","title":{"rendered":"Useradd comand"},"content":{"rendered":"<p>Today i just got a question on how actually a useradd command works and is it possible for us to create user without useradd command. And here is my answer after some googling around \ud83d\ude06<\/p>\n<p><span style=\"font-size: x-large;\">what is useradd ?<\/span><\/p>\n<p><strong id=\"y\">useradd COMMAND:<\/strong><br \/>\nuseradd &#8211; Adds new user to the linux system, with specified user-name. When a new user is added then a corresponding entry is made in files \/etc\/passwd, \/etc\/group and \/etc\/shadow<\/p>\n<p><strong id=\"y\">SYNTAX:<\/strong><br \/>\nThe Syntax is<br \/>\n<span style=\"color: brown;\">useradd [options] [username]<\/span><\/p>\n<p><strong id=\"y\">OPTIONS:<\/strong><\/p>\n<p># useradd &#8211;help<\/p>\n<p>Usage: useradd [options] LOGIN<\/p>\n<p>Options:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"319\" valign=\"top\">-b, &#8211;base-dir BASE_DIR<\/td>\n<td width=\"319\" valign=\"top\">base directory for the new user account home   directory<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-c, &#8211;comment COMMENT<\/td>\n<td width=\"319\" valign=\"top\">set the GECOS field for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-d, &#8211;home-dir HOME_DIR<\/td>\n<td width=\"319\" valign=\"top\">home directory for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-D, &#8211;defaults<\/td>\n<td width=\"319\" valign=\"top\">print or save modified default useradd configuration<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-e, &#8211;expiredate EXPIRE_DATE<\/td>\n<td width=\"319\" valign=\"top\">set account expiration date to EXPIRE_DATE<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-f, &#8211;inactive INACTIVE<\/td>\n<td width=\"319\" valign=\"top\">set password inactive after expiration to   INACTIVE<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-g, &#8211;gid GROUP<\/td>\n<td width=\"319\" valign=\"top\">force use GROUP for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-G, &#8211;groups GROUPS<\/td>\n<td width=\"319\" valign=\"top\">list of supplementary groups for the new user   account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-h, &#8211;help<\/td>\n<td width=\"319\" valign=\"top\">display this help message and exit<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-k, &#8211;skel SKEL_DIR<\/td>\n<td width=\"319\" valign=\"top\">specify an alternative skel directory<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-K, &#8211;key KEY=VALUE<\/td>\n<td width=\"319\" valign=\"top\">overrides \/etc\/login.defs defaults<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-m, &#8211;create-home<\/td>\n<td width=\"319\" valign=\"top\">create home directory for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-o, &#8211;non-unique<\/td>\n<td width=\"319\" valign=\"top\">allow create user with duplicate (non-unique) UID<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-p, &#8211;password PASSWORD<\/td>\n<td width=\"319\" valign=\"top\">use encrypted password for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-r, &#8211;system<\/td>\n<td width=\"319\" valign=\"top\">create a system account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-s, &#8211;shell SHELL<\/td>\n<td width=\"319\" valign=\"top\">the login shell for the new user account<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">-u, &#8211;uid UID<\/td>\n<td width=\"319\" valign=\"top\">force use the UID for the new user account<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong id=\"y\">EXAMPLE:<\/strong><\/p>\n<ol type=\"1\">\n<li>To add new user:\n<pre><span style=\"color: brown;\"># useradd test<\/span><\/pre>\n<p>This command will add a new user with name test.<\/li>\n<li>To add user but not allow to login in the system:\n<pre><span style=\"color: brown;\">useradd -s \/bin\/nologin test<\/span><\/pre>\n<p>This command will add user hiox but not allow to login. Or you can go to the \/etc\/passwd and set the test username\u00a0 <em>Shell access tobe <\/em>\/usr\/sbin\/nologin or \/usr\/sbinfalse<\/p>\n<h2>Understanding fields in \/etc\/passwd<\/h2>\n<p>The \/etc\/passwd contains one entry per line for each user (or user account) of the system. All fields are separated by a colon (:) symbol. Total seven fields as follows.<\/p>\n<p>Generally, passwd file entry looks as follows (click to enlarge image):<\/p>\n<p><a href=\"http:\/\/www.cyberciti.biz\/faqs\/uploaded_images\/passwd-file-791527.png\"><img decoding=\"async\" src=\"http:\/\/www.cyberciti.biz\/faqs\/uploaded_images\/passwd-file-783957.png\" border=\"0\" alt=\"\" \/><\/a><\/p>\n<ol type=\"1\">\n<li><strong>Username<\/strong>:      It is used when user logs in. It should be between 1 and 32 characters in      length.<\/li>\n<li><strong>Password<\/strong>:      An x character indicates that encrypted password is stored in \/etc\/shadow      file.<\/li>\n<li><strong>User ID (UID)<\/strong>:      Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for      root and UIDs 1-99 are reserved for other predefined accounts. Further UID      100-999 are reserved by system for administrative and system      accounts\/groups.<\/li>\n<li><strong>Group ID (GID)<\/strong>:      The primary group ID (stored in \/etc\/group file)<\/li>\n<li><strong>User ID Info<\/strong>:      The comment field. It allow you to add extra information about the users      such as user&#8217;s full name, phone number etc. This field use by finger      command.<\/li>\n<li><strong>Home directory<\/strong>:      The absolute path to the directory the user will be in when they log in.      If this directory does not exists then users directory becomes \/<\/li>\n<li><strong>Command\/shell<\/strong>:      The absolute path of a command or shell (\/bin\/bash). Typically, this is a      shell. Please note that it does not have to be a shell.<\/li>\n<\/ol>\n<table style=\"color: #3d366f; font-size: 13px; text-align: left;\" border=\"0\">\n<tbody>\n<tr>\n<td colspan=\"2\">In above command:<\/td>\n<\/tr>\n<tr style=\"color: brown;\">\n<td>test<\/td>\n<td>-Is the user-name<\/td>\n<\/tr>\n<tr style=\"color: brown;\">\n<td>\/bin\/nologin<\/td>\n<td>-Is Shell assigned to the user<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>To set expire date of the user:\n<pre><span style=\"color: brown;\">useradd -e 2008-06-30 test<\/span><\/pre>\n<p>This command will add user test and set the expire date to 2009-06-30.<\/p>\n<table style=\"color: #3d366f; font-size: 13px; text-align: left;\" border=\"0\">\n<tbody>\n<tr>\n<td colspan=\"2\">In above command:<\/td>\n<\/tr>\n<tr style=\"color: brown;\">\n<td>test<\/td>\n<td>-Is the user-name<\/td>\n<\/tr>\n<tr style=\"color: brown;\">\n<td>2009-06-30<\/td>\n<td>-Is date on which the user-account will be expired<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>To create user without creating home directory:\n<pre><span style=\"color: brown;\">useradd -M test<\/span><\/pre>\n<p>The above command will create user test but home directory will not be created.<\/li>\n<\/ol>\n<p>How to add user without useradd command ?<\/p>\n<p>as you probably know useradd command actualy create a user on \/etc\/passwd to determine the user id home directory comman shell etc, \/etc\/group to determine te group id and \/etc\/shadow for password. I will create a newtest username but since the password was encrpty MD5 i will use the previous username password on the newtest username that we will create withiut useradd command<\/p>\n<div style=\"margin: 5px 20px 20px;\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px;\">Code:<\/div>\n<pre class=\"alt2\" style=\"border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: auto; height: 178px;\"># useradd testing\r\n# passwd testing\r\nNew password: <em>password<\/em>\r\nRe-enter new password:<em> password<\/em>\r\nPassword changed.\r\n#\r\n# cat \/etc\/shadow | grep testing\r\ntesting:$1$AdHBr9EJ$VwEqlF.GprlX28oWWYprZ0:14313:0:99999:7:::\r\n#\r\n# cat \/etc\/passwd | grep testing\r\ntesting:x:1001:1001::\/home\/tesing:\/bin\/sh\r\n# cat \/etc\/group | grep testing\r\ntesting:x:1001:\r\n\r\nCreate newtest username without adduser command\r\n# vi \/etc\/shadow\r\nadd newtest password and save\r\nnewtest:$1$AdHBr9EJ$VwEqlF.GprlX28oWWYprZ0:14313:0:99999:7:::\r\n# vi \/etc\/group\r\nadd newtest username group and id (makesure u have use the new id number\r\nnewtest:x:1002:\r\n# vi \/etc\/passwd\r\nadd newtest username,id,home directory ,shell command\r\nnewtest:x:1002:1002::\/home:\/bin\/sh<\/pre>\n<\/div>\n<p>Of course, this is my version of creating a user without useradd command. Please correct me if i am wrong<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today i just got a question on how actually a useradd command works and is it possible for us to create user without useradd command. And here is my answer after some googling around \ud83d\ude06 what is useradd ? useradd COMMAND: useradd &#8211; Adds new user to the linux system, with specified user-name. When a [&hellip;]<\/p>\n","protected":false},"author":386,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1357],"tags":[1358],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-commands","tag-useradd-comand"],"_links":{"self":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/users\/386"}],"replies":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303"}],"version-history":[{"count":3,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions\/305"}],"wp:attachment":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}