Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove setgid (linux/unix)?

Tags:

I just changed my file permissions using $ sudo chmod g+s filename and my file permissions turned from drwxr-xr-x to drwxr-sr-x. How do I remove it?

like image 480
bigpotato Avatar asked Jan 25 '13 19:01

bigpotato


People also ask

What is setgid in Linux?

setgid() sets the effective group ID of the calling process. If the calling process is privileged (more precisely: has the CAP_SETGID capability in its user namespace), the real GID and saved set-group-ID are also set. Under Linux, setgid() is implemented like the POSIX version with the _POSIX_SAVED_IDS feature.

How do I remove a sticky bit in Unix?

In Linux sticky bit can be set with chmod command. You can use +t tag to add and -t tag to delete sticky bit.

How do I remove SUID and SGID?

To remove the setuid and setgid bits numerically, you must prefix the bit-pattern with a 0 (e.g.: 0775 becomes 00775 ).


2 Answers

Change the + for adding a permission into a - to remove it:

sudo chmod g-s filename 
like image 57
andrewdotn Avatar answered Oct 18 '22 21:10

andrewdotn


To remove setgid the numerical way the command is

sudo chmod 0664 $filename

The assumption here is the permission on file is 664 and we are not changing it. The left most bit in the above command represents setuid(4),setgid(2) and sticky(1). Now to represent these symbolically setuid is u+s, setgid is g+s and sticky is o+t

Example 1:-chmod u+s filename This will setuid for the filename mentioned that is rwsr_xr_x

Example 2: chmod 2770 directory This will set gid for the directory mentioned that is rwxr_sr_x

like image 22
DJAdmin Avatar answered Oct 18 '22 22:10

DJAdmin