Login | Sign up

May 23


0

Intro to setuid and setgid

Comments (0)

setuid and setgid are useful file permissions. Learn what they are, how to add and remove them and check if they were set successfully.

What are setuid and setgid

setuid and setgid are linux file permissions. When a file has one or both of these permissions and is executed, the file is executed as the owner or group owner regardless of who actually executed the file.

For example, we have a file called myprogram that is owned by root and has setuid set. Let's assume you are logged in as joe and you have execute permission. When you execute myprogram, the script will run as root instead of as joe.

setgid is the same as setuid except it changes the effective group to the owning group.

setgid on directories

When setgid is set on a directory, it does something completely different. Any file that is created inside a directory that has setgid will have the same group ownership as the parent directory with setgid.

How to add/remove setuid and setgid

The easier way to add setuid:

  1. chmod u+s <file>

The easier way to add setgid:

  1. chmod g+s <file>

To remove setuid and setgid, just change the above commands from +s to -s.

  1. chmod u-s <file>
  2. chmod g-s <file>

How to check for setuid and setgid

To check for either of these, display the file permission using:

  1. ls -l

An s where the user execute bit means setuid is on. If the s is a capital, it means the user does not have execute permission.

An s where the group execute bit means setgid is on. If the s is a capital, it means the group does not have execute permission.

  1. -r-sr-----   joe joegroup   file1
  2. -r-Sr-----   joe joegroup   file2
  3. -r--r-s---   joe joegroup   file3
  4. -r--r-S---   joe joegroup   file4

file1 - setuid is on and joe has execute
file2 - setuid is on but joe does not have execute
file3 - setgid is on and joegroup has execute
file4 - setgid is on but joegroup does not have execute


Comments

There are no comments yet.


Post a new comment

Note: Items marked * are required fields

Post a comment

You must login before you can do that.

If you don't have an account, register for free. It's completely private.

Why register

  • rate posts and comments
  • ask questions about posts
  • request new topics/tutorials
  • mark posts as favorites to easily find them again