<http://schema.org/articleBody>
"&amp;lt;p&amp;gt;Let&amp;amp;#39;s start by creating a simple user.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The following command will add a new user called test to your system:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sudo useradd test\u00A0&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;What will happen when this command is ran will depend on the contents of the configuration file located in /etc/default/useradd.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To view the contents of /etc/default/useradd run the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sudo nano /etc/default/useradd&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The configuration file will set a default shell which in &amp;lt;a href=&amp;quot;https://www.lifewire.com/things-to-do-installing-ubuntu-2200611&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;Ubuntu&amp;lt;/a&amp;gt; is bin/sh. All the other options are commented out.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The commented out options allow you to set a default home folder, a group, number of days after the password has expired before the account becomes disabled and a default expiry date.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The important thing to glean from the above information is that running the useradd command without any switches may produce different results on different distributions and it is all to do with the settings in the /etc/default/useradd file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;In addition to the /etc/default/useradd file there is also a file called /etc/login.defs which will be discussed later in the guide.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Important: sudo is not installed on every distribution. If it is not installed you need to log into an account with appropriate permissions for creating users&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The previous example was fairly simple but the user may or may not have been assigned a home directory based on the settings file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To force the creation of a home directory use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;useradd -m test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command creates a /home/test folder for the user test.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you want the user to have a home folder in a different place to the default you can use the -d switch.&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sudo useradd -m -d /test test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command will create a folder called test for user test under the root folder.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Note: Within the -m switch the folder may not be created. It depends on the setting within /etc/login.defs.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;In order to get this to work without specifying a -m switch edit the file /etc/login.defs and at the bottom of the file add the following line:&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;CREATE_HOME yes&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;Now that you have created a user with a home folder you will need to change the user&amp;amp;#39;s password.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To set a user&amp;amp;#39;s password you need to use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;passwd test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command will allow you to set the test user&amp;amp;#39;s password. You will be prompted for the password you wish to use.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can test your new user&amp;amp;#39;s account by typing the following into a terminal window:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;su - test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command switches user to the test account and assuming you created a home folder you will be placed in the home folder for that user.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you are working in an office and you have a new contractor starting who is going to be at your office for a short period of time then you will want to set an expiry date on his or her user account.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Similarly if you have family coming to stay then you can create a user account for that family member that expires after they have left.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To set an expiry date when creating a user, use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;\u00A0useradd -d /home/test -e 2016-02-05 test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The date must be specified in the format YYYY-MM-DD where YYYY is the year, MM is the month number and DD is the day number.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you have a new user joining your company then you might want to assign specific groups for that user so that they have access to the same files and folders as other members of their team.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;For example imagine you had a guy called john and he was joining as an accountant.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The following command would add john to the accounts group.&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;useradd -m john -G accounts&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The file /etc/login.defs is a configuration file which provides the default behaviour for login activities.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;There are some key settings in this file. To open the /etc/login.defs file enter the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sudo nano /etc/login.defs&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The login.defs file contains the following settings which you might want to change:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;PASS_MAX_DAYS - how long before a password expires\u00A0&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;PASS_MIN_DAYS - how often can a password be changed&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;PASS_WARN_AGE - number of days warning before a password expires&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;LOGIN_RETRIES - number of login attempts before failure&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;LOGIN_TIMEOUT - how long is it before the login times out.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;DEFAULT_HOME - can a user login if no home folder exists&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;Note that these are the default options and they can be overridden when creating a new user.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can set a password expiry date, the number of login retries and the timeout when creating a user.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The following example shows how to create a user with a password warning, maximum number of days before password expires and login retries set.&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sudo useradd test5 -m -K PASS_MAX_DAYS&amp;amp;#61;5 -K PASS_WARN_AGE&amp;amp;#61;3 -K LOGIN_RETRIES&amp;amp;#61;1&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;\u00A0If the login.defs file has the option &amp;lt;strong&amp;gt;CREATE_HOME yes\u00A0&amp;lt;/strong&amp;gt;set then when a user is created a home folder will automatically be created.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To create a user without a home folder regardless of the settings use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;useradd -M test&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;It is fairly confusing that -m stands for create home and -M stands for do not create home.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;As part of your user creation policy you might choose to do something like the first initial, followed by the last name. For example the username for &amp;amp;#34;John Smith&amp;amp;#34; will be &amp;amp;#34;jsmith&amp;amp;#34;.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;When looking for details about a user you might not then be able to distinguish between John Smith and Jenny Smith.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can add a comment when creating an account so it is easier to find out the user&amp;amp;#39;s real name.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The following command shows how to do this:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;useradd -m jsmith -c &amp;amp;#34;john smith&amp;amp;#34;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;\u00A0When you create a user the details of that user are added to the /etc/passwd file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To view the details about a particular user you can use &amp;lt;a href=&amp;quot;https://www.lifewire.com/linux-grep-command-3571842&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;the grep command&amp;lt;/a&amp;gt; as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;grep john /etc/passwd&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;\u00A0&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Note: The above command will return details about all users with the word john as part of the user name.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The /etc/passuword file contains a colon separated list of fields about each user.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The fields are as follows:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;username&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;encrypted password (which you obviously can&amp;amp;#39;t see)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;userid&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;user&amp;amp;#39;s group id&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;full name of the user&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;user&amp;amp;#39;s home directory&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;login shell&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;\u00A0If you found this guide useful try out the following guides:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/use-linux-sleep-command-3572060&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;How to use the sleep command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/output-text-to-the-screen-linux-echo-command-3572040&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;2&amp;quot;&amp;gt;How to use the echo command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/operating-systems-unix-vs-windows-2180225&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;3&amp;quot;&amp;gt;How to find the directory name&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/linux-grep-command-3571842&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;4&amp;quot;&amp;gt;How to use the grep command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/extract-tar-gz-files-2202057&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;5&amp;quot;&amp;gt;How to extract tar.gz files&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/introduction-to-linux-log-files-2192233&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;6&amp;quot;&amp;gt;An introduction to Linux log files&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/move-files-with-linux-mv-command-2201103&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;7&amp;quot;&amp;gt;How to move files with the mv command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/what-does-cd-do-terminal-window-2183856&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;8&amp;quot;&amp;gt;What does cd ~ do&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/install-deb-packages-2205641&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;9&amp;quot;&amp;gt;How to install .deb files&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/what-are-hard-links-2190041&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;10&amp;quot;&amp;gt;What are hard links and why would you use them&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/download-file-from-command-line-2202055&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;11&amp;quot;&amp;gt;How to download a file from the command line&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/download-youtube-videos-p2-2202105&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;12&amp;quot;&amp;gt;How to download Youtube videos&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/show-system-information-terminal-with-screenfetch-2201159&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;13&amp;quot;&amp;gt;How to use screenfetch&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;"^^<http://www.w3.org/2001/XMLSchema#string>
<https://www.lifewire.com/create-users-useradd-command-3572157>