Lesson 6 - User and Group Management on Ubuntu

28/06/2024 - 3 phút

Follow  on Google News

In this lesson, we will learn how to manage users and groups in the Linux system. Managing users and groups is an important part of ensuring security and organization in the system. We will learn how to create and manage users, manage groups, and set access permissions using basic commands such as adduser, deluser, usermod, groupadd, groupdel, groupmod, chmod, chown, and chgrp.

1. Creating and Managing Users

CommandDescriptionExample
adduserCreate a new user in the systemsudo adduser username
deluserRemove a user from the systemsudo deluser username
usermodModify the information of an existing usersudo usermod -aG groupname username

2. Managing Groups

CommandDescriptionExample
groupaddCreate a new group in the systemsudo groupadd groupname
groupdelRemove a group from the systemsudo groupdel groupname
groupmodModify the information of an existing groupsudo groupmod -n newgroupname oldgroupname

3. Permissions and Access Rights

CommandDescriptionExample
chmodChange the access permissions of a file or directorysudo chmod 755 filename
chownChange the owner of a file or directorysudo chown user:group filename
chgrpChange the group ownership of a file or directorysudo chgrp groupname filename

1. Creating and Managing Users

adduser: Create New User

The adduser command is used to create a new user in the system.

CommandDescriptionExample
adduserCreate a new usersudo adduser username

Example:

sudo adduser username

This command will create a new user named username and prompt you to enter detailed information such as password, full name, and contact information.

deluser: Remove User

The deluser command is used to remove a user from the system.

CommandDescriptionExample
deluserRemove a usersudo deluser username

Example:

sudo deluser username

This command will remove the user username from the system.

usermod: Modify User Information

The usermod command is used to modify the information of an existing user.

CommandDescriptionExample
usermodModify user informationsudo usermod -aG groupname username

Example:

sudo usermod -aG groupname username

This command will add the user username to the group groupname.

2. Managing Groups

groupadd: Create New Group

The groupadd command is used to create a new group in the system.

CommandDescriptionExample
groupaddCreate a new groupsudo groupadd groupname

Example:

sudo groupadd groupname

This command will create a new group named groupname.

groupdel: Remove Group

The groupdel command is used to remove a group from the system.

CommandDescriptionExample
groupdelRemove a groupsudo groupdel groupname

Example:

sudo groupdel groupname

This command will remove the group groupname from the system.

groupmod: Modify Group Information

The groupmod command is used to modify the information of an existing group.

CommandDescriptionExample
groupmodModify group informationsudo groupmod -n newgroupname oldgroupname

Example:

sudo groupmod -n newgroupname oldgroupname

This command will change the group name from oldgroupname to newgroupname.

3. Permissions and Access Rights

chmod: Change Access Permissions

The chmod command is used to change the access permissions of a file or directory.

CommandDescriptionExample
chmodChange access permissionssudo chmod 755 filename

Example:

sudo chmod 755 filename

This command will change the access permissions of filename to 755.

chown: Change Owner

The chown command is used to change the owner of a file or directory.

CommandDescriptionExample
chownChange ownersudo chown user:group filename

Example:

sudo chown user:group filename

This command will change the owner of filename to user and group group.

chgrp: Change Group Ownership

The chgrp command is used to change the group ownership of a file or directory.

CommandDescriptionExample
chgrpChange group ownershipsudo chgrp groupname filename

Example:

sudo chgrp groupname filename

This command will change the group ownership of filename to groupname.

Conclusion

Through this lesson, you have mastered how to manage users and groups in the Linux system, as well as how to assign access permissions to files and directories. These skills are very important to ensure security and organization in the system. I wish you successful practice and application of this knowledge in your daily work.