Operating System - Linux
1748268 Members
3652 Online
108760 Solutions
New Discussion юеВ

Re: setuid setgid ? pls Help

 
SOLVED
Go to solution
Maaz
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,
Maaz
4 REPLIES 4
Jeroen Peereboom
Honored Contributor
Solution

Re: setuid setgid ? pls Help

Maaz,

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.

JP
Maaz
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

Maaz
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
or
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...
Maaz
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.

Regards
Maaz