Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

setuid setgid ? pls Help

Go to solution
Valued Contributor

setuid setgid ? pls Help

Hi Gurus
Why and What are setuid and setgid??? which command is used to set 'setuid' and 'setgid'
on a file.
B4 posting this question on forum, I tried to learn man pages, but didnt get the reason and usage of setuid and setgid, so Please Please TeAcH and/or ExPlaiN ... and if possible by ExamPleS

Second, i issue '$cat /etc/fstab' and found "none /dev/pts devpts gid=5,mode=620"
please also le me know whats 'gid=5' and 'mode=620' ?

Many Thanks In Advance
Best Regards,
Jeroen Peereboom
Honored Contributor

Re: setuid setgid ? pls Help


you login using an account.
If you start a program it runs with that account, which means that (for exapmle) privileges to write to a file are based on your account.
If the program you run is 'setuid', it runs which the file-owner account. For example, the /usr/bin/passwd command is setuid root.
This means that if you run this program. you 'are' temporarily root. This means you can write to the /etc/passwd file (which is writable to root only).

setgid is the same, but for the group the file belongs to.

chmod 4750 file:
4 -> setuid
7 =4+2+1= r+w+x for user
5 =4+1 = r + x for group
0 = nothing for others

gid=5 -> group id = 5
grep :5: /etc/group tells it's the 'tty' group.
Mode 620: user read/write, group write, others nothing.

Valued Contributor

Re: setuid setgid ? pls Help

Many Thanks Jeroen
but please also le me know how to set gid on a file ... chmod 4760 will sets suid not gid.
Second when I should set gid/suid on a file??? I mean when it is recommended or in which scenario one shold set suid/gid on a file

Stuart Browne
Honored Contributor

Re: setuid setgid ? pls Help

Ok, 4 octets:

1st: 4 = setuid, 2 = setgid, 1 = set sticky
2nd: (user) 4 = read, 2 = write, 1 = execute
3rd: (group) 4 = read, 2 = write, 1 = execute
4th: (other) 4 = read, 2 = write, 1 = execute

To set GUID on a file use one of the following:

chmod g+s file
chmod 2 file

This is all explained in the 'chmod' man page.

As for the 'fstab' entries, it's stating it wants that mount point (/dev/pts) to have group-id of 5, and all files under it (pts device nodes in this case) to have 620 permissions (-rw-w----).

.. oh, Jereon explained that already ..
One long-haired git at your service...
Valued Contributor

Re: setuid setgid ? pls Help

Stuart Browne, Many Many thanks for ur kind Feedback.

I do agree with u Stuart, i.e Jeroen Peereboom explained me so nice.