To add a New User Account & Set Password
To add or create the user account you need to use the "useradd" or "adduser" command with "username". The username is the login name of the user that is used by a user to log-in into system.
Syntax:
# useradd username
# passwd username
Example:
# useradd Rahul
# passwd Rahul@dev
Verify:
# cat /etc/passwd |grep Rahul
To create a user with different Home Directory
By default 'useradd' command creates a user's home directory under /home directory with username.
However the action can be changed by using (-d) option along with the location of new home directory ( i.e /etc/rahul ). For example the following command will create a user "Amit" with a home directory ' /etc/rahul'.
Syntax:
# useradd -d (home directory) (username)
Example:
# useradd -d /etc/rahul Amit
Verify:
# cat /etc/passwd |grep Amit
Create a user account with specific User ID (UID) & Group ID (GID)
In Linux, every user has its own UID by default, whenever we create a new user account. But we can create user account with custom userid with (-u) option. for example the following command will create a user 'Rahul' with custom UID '1050'
Syntax:
# useradd -u (custom UID) (username)
Example:
# useradd -u 1050 Rahul
Verify:
# cat /etc/passwd |grep Rahul
Similarly, Every user has its own GID. We can creates user with specific group ID as well with (-g) option.
Syntax:
# useradd -u (custom UID) -g (custom GID) (username)
Example:
# useradd -u 1050 -g 1010 Rahul
Verify:
# cat /etc/passwd | grep Rahul
# cat /etc/group | grep Rahul
Add a User to multiple Group
The (-G) option is used to add a user to additional group. Each group name is separated bye comma with no intervening spaces.
In the given example, I am going to add user "Rahul" into multiple group like admin1,admin2 & admin3.
# useradd -G admin1,admin2,admin3 Rahul
Now execute one of the following command to verify the multiple groups assigned to the user :
# id Rahul
# groups Rahul
Add a user without Home Directory
To create user without their home directories, (-M) option is used with useradd command. For example, the following command will create a user "Rahul" without home directory.
Syntax:
# useradd -M (username)
Example:
# useradd -M Rahul
Verify:
# cat /etc/passwd |grep Rahul
# ls -l /home/Rahul
Create a user with account expiry date
By default when we add user's with "useradd" command, user account never get expires. i.e there expiry date is set to 0 ( means never expired)
However we can set the expiry date using (-e) option that sets date in YYYY-MM-DD format. This is helpful for creating temporary account for a specific period of time.
Now we create a user "Rahul" with account expiry date i.e 3rd may 2018.
# useradd -e 2018-05-03 Rahul
To verify the age of account and password, execute the following command
# chage -l Rahul
Create a user account with password expiry date
The (-f) option is used to define the number of days after a password expires. A value of "0" inactive the user account as soon as the password has expired. By default, the password expiry value set to "-1" means never expire.
Example:
we will set an account password expiry date i.e. 2 days on a user "Rahul" using "-f " options.
# useradd -f 2 Rahul
To verify the user password expiry date, execute on of the command:
# cat /etc/shadow |grep Rahul
or
# passwd -S Rahul
Add a user with custom comments
The (-c) option allow you to add custom comments, such a user's full name, phone no, etc to '/etc/passwd' file. The comment can be added as a single line without any spaces.
for example:
The following command will add user "Rahul" and would insert the user's full name,"RahulDev" into the comment field.
# useradd -c "RahulDev" Rahul
Now you can see your comments in
# cat /etc/passwd |grep Rahul
Change user account login shell
sometimes, we add users which has nothing to do with login shell or sometimes we require to assign different shells to our users. we can assign different login shell to each user with (-s) option.
In the given example, I am going to add a user 'Rahul' without login shell.
i.e /sbin/nologin shell.
# useradd -s /sbin/nologin Rahul
To verify the assigned shell to the user in
# cat /etc/passwd /Rahul
To add or create the user account you need to use the "useradd" or "adduser" command with "username". The username is the login name of the user that is used by a user to log-in into system.
Syntax:
# useradd username
# passwd username
Example:
# useradd Rahul
# passwd Rahul@dev
Verify:
# cat /etc/passwd |grep Rahul
To create a user with different Home Directory
By default 'useradd' command creates a user's home directory under /home directory with username.
However the action can be changed by using (-d) option along with the location of new home directory ( i.e /etc/rahul ). For example the following command will create a user "Amit" with a home directory ' /etc/rahul'.
Syntax:
# useradd -d (home directory) (username)
Example:
# useradd -d /etc/rahul Amit
Verify:
# cat /etc/passwd |grep Amit
Create a user account with specific User ID (UID) & Group ID (GID)
In Linux, every user has its own UID by default, whenever we create a new user account. But we can create user account with custom userid with (-u) option. for example the following command will create a user 'Rahul' with custom UID '1050'
Syntax:
# useradd -u (custom UID) (username)
Example:
# useradd -u 1050 Rahul
Verify:
# cat /etc/passwd |grep Rahul
Similarly, Every user has its own GID. We can creates user with specific group ID as well with (-g) option.
Syntax:
# useradd -u (custom UID) -g (custom GID) (username)
Example:
# useradd -u 1050 -g 1010 Rahul
Verify:
# cat /etc/passwd | grep Rahul
# cat /etc/group | grep Rahul
Add a User to multiple Group
The (-G) option is used to add a user to additional group. Each group name is separated bye comma with no intervening spaces.
In the given example, I am going to add user "Rahul" into multiple group like admin1,admin2 & admin3.
# useradd -G admin1,admin2,admin3 Rahul
Now execute one of the following command to verify the multiple groups assigned to the user :
# id Rahul
# groups Rahul
Add a user without Home Directory
To create user without their home directories, (-M) option is used with useradd command. For example, the following command will create a user "Rahul" without home directory.
Syntax:
# useradd -M (username)
Example:
# useradd -M Rahul
Verify:
# cat /etc/passwd |grep Rahul
# ls -l /home/Rahul
Create a user with account expiry date
By default when we add user's with "useradd" command, user account never get expires. i.e there expiry date is set to 0 ( means never expired)
However we can set the expiry date using (-e) option that sets date in YYYY-MM-DD format. This is helpful for creating temporary account for a specific period of time.
Now we create a user "Rahul" with account expiry date i.e 3rd may 2018.
# useradd -e 2018-05-03 Rahul
To verify the age of account and password, execute the following command
# chage -l Rahul
Create a user account with password expiry date
The (-f) option is used to define the number of days after a password expires. A value of "0" inactive the user account as soon as the password has expired. By default, the password expiry value set to "-1" means never expire.
Example:
we will set an account password expiry date i.e. 2 days on a user "Rahul" using "-f " options.
# useradd -f 2 Rahul
To verify the user password expiry date, execute on of the command:
# cat /etc/shadow |grep Rahul
or
# passwd -S Rahul
Add a user with custom comments
The (-c) option allow you to add custom comments, such a user's full name, phone no, etc to '/etc/passwd' file. The comment can be added as a single line without any spaces.
for example:
The following command will add user "Rahul" and would insert the user's full name,"RahulDev" into the comment field.
# useradd -c "RahulDev" Rahul
Now you can see your comments in
# cat /etc/passwd |grep Rahul
Change user account login shell
sometimes, we add users which has nothing to do with login shell or sometimes we require to assign different shells to our users. we can assign different login shell to each user with (-s) option.
In the given example, I am going to add a user 'Rahul' without login shell.
i.e /sbin/nologin shell.
# useradd -s /sbin/nologin Rahul
To verify the assigned shell to the user in
# cat /etc/passwd /Rahul
Buy microsoft office 2016 home & student (1 MAC) (MAC Version) and Get Life Time License for Word, Excel, PowerPoint, and One Note. You can store files in the Cloud with OneDrive. OneNote notebooks help you easily organize your notes and find just what you need fast. Share notebooks to simplify group projects.
ReplyDelete