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=1001
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no

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
To set Password for user
The sort command is used to sort the contents of a file. You can sort the data in a text Read more
sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more
Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more
To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more