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

Máy Tính
TOP 4 Laptop Dưới 15 Triệu
Phần Mềm
Cách THEO DÕI ĐIỆN THOẠI không cần CÀI ĐẶT
Tổng Hợp
Hướng dẫn cách làm kẹp sách bằng giấy cực kỳ dễ thương | Làm đánh dấu sách xinh xắn | Dạy bé học
  • I think this guy must be deaf or mute because he (or she) never says anything! 😐