How to set the SGID bit on a Directory on CentOS 6.2 Linux Server

Share this Article :

SetGID or “set group ID upon execution” are the Unix access rights flags that allow users to run an executable with the permissions of the executable’s group. They are often used to allow users on a computer system or group to run programs with temporarily elevated privileges in order to perform a specific task. In this post, i will show the command that would set the SGID bit on the /home/ehowstuff directory on CentOS 6.2. At most cases, SetGID or SGID are needed for tasks that require higher privileges than those which common users have, such as changing their login password.

Default permission on the /home/ehowstuff directory as below :

[[email protected] ~]# ls -l /home | grep ehowstuff
drwx------. 2 ehowstuff ehowstuff 4096 Jan 29 21:18 ehowstuff

There are two different commands that available to set the SGID bit on the /home/ehowstuff directory. If that’s all you want to do, run the following command:

[[email protected] ~]# chmod g+s /home/ehowstuff

Result :

[[email protected] ~]# ls -l /home | grep ehowstuff
drwx--S---. 2 ehowstuff ehowstuff 4096 Jan 29 21:18 ehowstuff

Alternatively, if you’re also assigning full user and group permissions to /home/ehowstuff, you could run the following command:

[[email protected] ~]# chmod 2770 /home/ehowstuff

Result :

[[email protected] ~]# ls -l /home | grep ehowstuff
drwxrws---. 2 ehowstuff ehowstuff 4096 Jan 29 21:18 ehowstuff

Leave a Reply