/ linux

Linux Tip of the Week: Cool Permissions

Today is the start of a new week! Well, for a lot of us. I know some of you crazy, eccentric people start your week on Monday. You can stick around, but start your counter at 1.

This is the start of a weekly segment to share some cool Linux tips. Some of the write ups will be long, probably 5 minutes of read time :O – Others will be brief, maybe a command or two and a screen shot.

The topic today is probably going to be the latter. Some time recently, I came across an interesting configuration at work. Having put in some time for the RHCSA/RHCE exams, I was a bit embarrassed that I didn't know what a permission setting meant. It turns out that it's very common for file sharing.

chmod 02744

The 2 is what was in question here, for me anyway. It sets up a GroupID for the folder, which means that any file created inside will share the same group. Let's look at two examples below.

Folder_1

Pretty standard stuff so far. So, let's create some files.

cd Folder_1
touch test.txt
sudo su
touch test2.txt
exit
ll

The last command, 'll', is an alias I have setup. If it doesn't work on your box just run 'ls -la' for similar output.

Note the user and group:

The file created by root is part of the root user and root group.

Let's create another folder, Folder_2, and enter the chmod command above:

cd ..
mkdir Folder_2
chmod 02744 Folder_2
ls -ld Folder_*

Now, on Folder_2, under the group we have the 'S' value. Let's repeat the file creation example from above in Folder_2:

cd Folder_2
touch test.txt
sudo su
touch test2.txt
exit
cd .. 
ll Folder_*

Here we can see the contents of Folder_1 and Folder_2. Note the exact same files and owners. In Folder_2, we see that the user for test2.txt is root, but the group is chris. How awesome is that? This is very useful when you have a shared directory or a group that needs to collaborate on a project together.

This also works on sub-directories. Try it yourself. In Folder_2 create another directory and add files with different users, including root.

Let me know if you have any feedback or ideas for these segments! Thanks for reading! Happy hacking!

Linux Tip of the Week: Cool Permissions
Share this