Creating group folders for Linux users
You may have watched several youtube videos or read several articles on how to create, delete or modify a group. You may have also learned how to add a user to a group. I too have written an article on that. But do you know how we can use these groups and bring them into action? How we can modify the group so that the users of the group can access a particular file whereas the users who are not in that group cannot access that file? Today in this blog I'm going to show you how we can do this.
So let's begin:
If you don't have a group already created, create one.
Created a
devops
group.Add users to that group, and if do not have users created, create a few users too.
For me, I have created a
devops
group anduser1, user2, user3
as my users.Now I add my
user1
,user2
andubuntu
to thedevops
group after you have done that redirect yourself to theusr
directory.You can choose any other directory too but I would prefer to use
usr
directory.Create a directory that you wish to make a group directory I would create a directory
devopsfile
Now change the group owner from root to
devops
(the group which I have created).
Now change the permission of your directory for group users and give them read, write and sticky access.
The sticky access for the group users is important. It gives access to other users of the same group to access the file and modify it. If this is not done, other users of the same group have permission to just read not write.
Now let's create a .txt file name
hello.txt
in thedevopsfile
directory.You can also see the .txt file which I created and edited has a group user
devops
. So every other user of thedevops
group can now access thehello.txt
file and edit it easily but any user who is not in thedevops
group can read the file. If we want that any user who is not a part ofdevops
group has no access to our files we can change the access permission for that too.Now any user who is not in the
devops
group will not be able to view any file in thedevops
file directory.So this is a simple but mind-blowing example of how groups work. Hope you got some insights.