chmod SGID bit (s-flag in permissions)?

While going through some questions for an upcoming exam we came across the following:

drwxrwsr-x 2 user group 6 Oct  3 08:14 folder

In particular, the ‘s’ flag in the permissions. I did some research and found the following:

This is the setuid/setgid bit and its function changes depending on whether it’s set on a directory or a file.

When set on an executable file, the setuid bit will mean it will be executed with the permissions of its owner, while the setgid bit will mean it will be executed with those of its owning group.

This is usually done if want to allow a ‘normal’ user to execute a command or binary with root permissions. An example of this is the passwd command which requires root permissions to change passwords but users need to be able to change their own passwords without giving them root access.

On directories however, when the setgid bit is set any files created or copied into the directory will be inherit its group ID rather than the ID of the user modifying the file. This means files created in a shared space will automatically be accessible by those in the directory’s group. This saves the user having to manually modify the group each time they create or copy a file into the directory.

The setuid bit on directories is generally ignored by Linux.

Hope that clears it up! You can find more information on its wikipedia page.

Advertisements

Published by:

Skyrail

Production Facilitator at Audacious Church Previously Software Developer at UKFast Ltd. and Web Applications Developer at SenseLogix Ltd. Graduate of Renewable Energy BSc from the University of Exeter. Experience with PHP, MySQL, Javascript, CSS and HTML.

Categories An Introduction to, LinuxLeave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s