6 ms·
One of the most useful group-related tricks (introduced in BSD Unix, I believe) is the setgid bit on a directory. If this is set, new files and subdirectories
by ScottBurson 9y ago
One of the most useful group-related tricks (introduced in BSD Unix, I believe) is the setgid bit on a directory. If this is set, new files and subdirectories created within the directory will have the same group as the directory, rather than the group of the process that created them.
- jaymzcampbell 9y agoI use this as a basic indicator of someone's Unix competency. Not as a straight binary thing, but if I'm talking to someone (interviewing or maybe debugging something) I've found that if you know about setgid/setuid you have probably been interested enough to know what you are doing.
- eru 9y agoI've seen interviewers ask for the sticky bit and the difference between hard and soft links as similar shibboleths.
- dozzie 9y agoI've seen them ask how to restore execution permissions after `chmod a-x /bin/chmod'. I usually answer to those smartasses that I my favourite way is to run the very non-executable /bin/chmod without any file juggling. I'm yet to meet anybody who wasn't surprised that it's possible.
- pnutjam 9y agoexplain?
- shabble 9y agoshabble@host:~$ cp /bin/chmod /tmp/chmoo shabble@host:~$ chmod 600 /tmp/chmoo shabble@host:~$ ll /tmp/ch* -rw------- 1 shabble shabble 59K Nov 21 17:15 /tmp/chmoo shabble@host:~$ /tmp/chmoo -bash: /tmp/chmoo: Permission denied shabble@host:~$ /lib64/ld-linux-x86-64.so.2 /tmp/chmoo /tmp/chmoo: missing operand Try '/tmp/chmoo --help' for more information.
- ansible 9y agoWell, that's a new one on me. I'd just have 'cat'ted the chmod executable onto some other executable, which keeps the permissions.
- AnIdiotOnTheNet 9y agoThis technique fails if chmod is compiled statically.
- mnarayan01 9y agoManually call e.g. /lib/ld-linux.so.2 (man ld.so for more info).
- jandrese 9y agoI'm a little surprised some smartypants hasn't come along and added a check to ld to prevent this from working, probably for "security" reasons. I've known about this trick for a long time, but I've always thought its days were numbered. Another way to solve the problem: scp unfuckedhost:/bin/chmod . ./chmod (stuff)
- fapjacks 9y agoThis is my go-to method for doing that. Years ago, in the 90s, I used that trick (with ftp) to overwrite a custom login script used to "prevent" users from logging in. You'd login and it would spit out like "You are not allowed to login!" and then immediately log you out. Well, ftp (this is before sftp or scp) let me copy over that. This was actually one of the computers used by the newspaper in the next town over. I'm still shocked actually that the worst I ever got from the sysadmin there was a stern phone call.
- agumonkey 9y agoI've worked around this without knowing about setgid ... It's funny how easily I suffer tiny papercuts that way, it should be obvious "there's a better way".
- deleted 9y ago[deleted]
- Iolaum 9y agoI finally created an account specifically to upvote this. I have created a shared folder in my laptop, running Ubuntu, with symbolic links from 2 users home directories (to avoid having data (mostly photos) stored twice) and manually fixing the group of new files has been a chore! Thanks!!
- dozzie 9y ago[dozzie@zorn /srv]$ ls -ld foo drwxrwxrwx 2 root wheel uarch 2 Nov 21 12:57 foo/ [dozzie@zorn /srv]$ touch foo/nabla [dozzie@zorn /srv]$ ls -l foo/nabla -rw-r--r-- 1 dozzie wheel uarch 0 Nov 21 12:58 foo/nabla [dozzie@zorn /srv]$ id uid=1001(dozzie) gid=1001(dozzie) groups=1001(dozzie) [dozzie@zorn /srv]$ uname -s -r FreeBSD 11.0-RELEASE-p1 This is called "BSD semantics". You can get the same behaviour with appropriate mount option for Ext2/3/4 and XFS.
- jwilk 9y agoWhat filesystem was that? And why is this behavior filesystem-specific?
- dozzie 9y agoNot what filesystem, it's what OS. FreeBSD. And ZFS, but UFS works the same.
- laumars 9y agoI could be wrong but I thought the file system's "drivers" did the handling of file system permissions rather than the OS / kernel? Or at least this was my experience when playing around with FUSE on hobby projects.
- jwilk 9y agoSo why did you mentation "Ext2/3/4 and XFS" if filesystem doesn't matter?
- dozzie 9y agoI don't see what you don't understand. I demonstrated that on FreeBSD created file inherits the group of its parent directory even without SGID, i.e. that FreeBSD exhibits BSD semantics. I also added that if you can have BSD semantics on Ext2/3/4 and XFS if you mount them under Linux with appropriate options.