How to add User & group in Linux

How to manage user in linux 

User add or modified 

In linux we can add the user or modified user  using only root user. A root user is a super user in linux.

1. Useradd  command 

This command is add the user. Defiant the user name and user id or email etc. it single command two way add the user details full or second only username.                                                                                                                                   -u [user id] ,  -m -d [user directory] , -k [skel file cpoy in user directory] , -c [common  user name ]

# useradd -u 1002 -m -d /data/users/xyz -k /etc/skel -c "xyx pqr" xyz
# useradd [USERNAME] (automatically add the user)

Check the user detail using the cat command

# cat /etc/passwd 
# tail /etc/passwd

In above image 1. user ,  2. password , 3. User ID (UID) , 4. Group ID (GID), 5.User ID Info (GECOS), 6. Home directory, 7. Command/shell

2. Assign password user

This command assign password user then after you can accesses user other vice cannot accesses user. Then after add password two time.

# passwd [USERNAME]
# paaswd xyz  

3. User add in group 

User add into the group using the usermod command

# usermod -aG [GROUP NAME] [USERNAE]
# usermod -aG tech xyz

4. Delete user 

This command is delete the user  but use  -r  for the remove all the file and directory in side the user.

# userdel -r [USERNAME]
# userdel -r xyz

5. Su command 

This command is use for switch user. If login root user change normal user using su command one user to second user switch. then after enter the password of use to login.

# su xyz

6. Create group & add user in cloup 

Using the command we crate a group in linux

# groupadd [OPTION] 
# groupadd it

After crate group add the user in to group and use -aG for user add more than group not remove or  replace old group of user . -g is use for add in to the primary group add in to user

# useradd -aG [GROUPNAME] [USERNAME]
# useradd -aG it xyz
# useradd -g it xyz

7. Change ownership or group 

In this command change the user and file/directory  owner or group.  run chown command first is owner name  add  : then after group name last file or directory name

# chown   xyz:it  [OPTION OR USERNAME]  
# chown  xyz:it  xyz

one more command is use for only change the group

# chgrp it xyz

8. Delete group

This command is use for delete a group.

# groupdel [OPTIONS] [GROUPNAME]
# groupdel it 


Was this article helpful?

Related Articles