DelphiFAQ Home Search:

How to set the setuid and setgid bit for files in Unix

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I need to set setuid and setgid bit for files.
Please show me how to. And what is the exact purpose of the uid bit?

Answer:

In the shell just type the commands shown in the box below to set the uid or gid bits.

The purpose of the uid bit:
If you change an executable file to have the setuid bit set then when any other user runs this executable the effective user ID of the process will be switched to the user that owns the file. The same way, if you set the gid bit, then the process will be executed under the group of the file. You have to be very careful with this feature as one can easily create a hard-to-spot security whole with it.
The purpose is usually to give the executable file the ability to write to a certain file - e.g. a log file - that the regular user cannot write to. When it runs under the owner's ID, it can write to that file.
Having the process execute under a different user id has some other side effects for example coredumps are disabled and the C runtime library ignores or deletes some environment variables.

// setuid
chmod 4555   executable_file

// setgid
chmod 2555   executable_file

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.