[Linux] user & user group manage
Example
Summarized Answer:
Create a dedicated group (e.g.,
SOME_GROUP
assign team users to this group.Establish a shared directory with group ownership and set the setgid bit using
chmod 2770
so that new files inherit the group.Use specific commands to create the user
some_group_some-user
and assign them as the first member of the team.
Detailed Answer:
Group Creation:
Begin by creating a group for the team named
SOME_GROUP
using the command:This group will serve as the common owner for the shared directory and all its files.
User Creation and Group Assignment:
Create the user with the specified username and assign the user to the SOME_GROUP group. For the user
some_group_some-user
, execute:This command creates the user and automatically adds them to the
SOME_GROUP
group as their primary group.If the user already exists, add them to the group using:
Creating the Shared Directory:
Decide on a common location for the shared directory (for example,
/srv/SOME_GROUP
):Change the group ownership of this directory to the
SOME_GROUP
group:
Understanding and Setting Permissions (
chmod 2770
):The command
chmod 2770 /srv/SOME_GROUP
sets the directory permissions and is broken down as follows:The first digit
2
sets the setgid (set group ID) bit. This means any new files or directories created inside/srv/SOME_GROUP
will inherit the groupSOME_GROUP
automatically, ensuring that all team members maintain proper group ownership.The next digit
7
gives the owner (here,root
) read, write, and execute permissions.The following digit
7
gives the group (SOME_GROUP
) read, write, and execute permissions.The final digit
0
denies any permissions for others (users not in theSOME_GROUP
group).
Execute this command as follows:
Verifying the Configuration:
Use
ls -ld /srv/SOME_GROUP
to check that the permissions are set correctly. The output should resemble:The
s
in the group permissions field confirms that the setgid bit is active.
By following these steps, you establish a secure shared directory for the SOME_GROUP
team. Users added to the SOME_GROUP
group will be able to create and manage files within /srv/SOME_GROUP
while automatically inheriting the proper group ownership, ensuring effective collaboration and file management within the team.
Last updated
Was this helpful?