How to Create, List, Add, Edit, Assign and change user groups, and Delete Users and Groups in Linux

Commands used:

1. list users
– show current user
– list all users
#cat /etc/passwd -or- #getent passwd

2. list groups
– show groups for current user
– show groups for a user
#groups username
– list all groups
#cat /etc/group -or- #getent group

3. Create a New User
– Create a New User
#useradd username
this command will create user and a group will also created for the new user with the same name
– Create a New User and Assign a Group in one command
#useradd -G groupname username
#useradd -G group1,group2,group3 username

4. change user password or set password for the new user
– #passwd username

5. add new group
– #groupadd newgroup

6. Add existing User to a Group
– add a User to a Group
#usermod -a -G group username
– add a User to Multiple Groups
#usermod -a -G group1,group2,group3 username

7. Removing user from group
– #gpasswd -d username group

8. Change User Primary Group
– #usermod -g group user
Note: -g lowercase to assign user primary group

9. delete groups
– #groupdel groupname

10. delete user
– #userdel username
– #userdel -r username
Note: -r option to remove user’s home directory and the user’s mail spool


Xem thêm bài viết khác:

1 Comment

Bilal Heuser

May 16, 2020

I think this guy must be deaf or mute because he (or she) never says anything! 😐


Leave a Reply