To add a user in Linux, you can use useradd command. Refer below syntax:
useradd [options]. To view the options use same command with the option -D.
Example: useradd anil
While creating users as mentioned above, all the default options will be taken except group id. To view, the default options give the following command with the option -D.
$ useradd -D
|GROUP||This is the only option which will not be taken as default. Because if you don’t specify -n option a group with same name as the user will be created and the user will be added to that group. To avoid that and to make the user as the member of the default group you need to give the option -n.|
|HOME||This is the default path prefix for the home directory. Now the home directory will be created as /home/USERNAME.|
|INACTIVE||-1 by default disables the feature of disabling the account once the user password has expired. To change this behavior you need to give a positive number which means if the password gets expired after the given number of days the user account will be disabled.|
|EXPIRE||The date on which the user account will be disabled.|
|SHELL||Users login shell.|
|SKEL||Contents of the skel directory will be copied to the users home directory.|
|CREATE_MAIL_SPOOL||According to the value creates or does not create the mail spool.|
To create a user in Linux with custom configurations
To change default options in configuration file
To change existing User's Home Directory
You need to use the usermod command to set the user’s new login directory.
Syntax: usermod -m -d /path-to-new-home-dir userName
-d dirnanme : Path to new login (home) directory.
-m : The contents of the current home directory will be moved to the new home directory, which is created if it does not already exist.
Example: usermod -m -d /users/linuxinanutshell/anil anil
In the above example set the user’s new login directory to /users/linuxinanutshell/anil from /home/anil