Lập Trình Linux

Users and Groups in Linux : Create, List, Add, Edit, Assign, and Delete




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
#users
– list all users
#cat /etc/passwd -or- #getent passwd

2. list groups
– show groups for current user
#groups
– 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
-or-
#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

Nguồn: https://ftlinuxcourse.com

Xem thêm bài viết khác: https://ftlinuxcourse.com/lap-trinh-linux

Lập Trình Linux
Microsoft cho phép dùng nhân Linux tùy chỉnh trên Windows 10 – Tin Tức Chọn Lọc
Tin HOT
Trường hợp thứ 35 mắc COVID-19 tại Việt Nam | COVID-19 diễn biến phức tạp tại Châu Á | VTV24
Tin HOT
Lại đốt xác? Tình hình dịch bệnh khẩn cấp ở Cáp Nhĩ Tân, nồng độ PM2.5 cao gấp 4.000 lần
  • I think this guy must be deaf or mute because he (or she) never says anything! 😐