Live data from Hacker News

How do groups work on Linux?

jvns.ca

61–68 of 68 posts

Re: How do groups work on Linux?

#61

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.

I 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.

I 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!!

Re: How do groups work on Linux?

#62
post #47
post #42

Earlier quoted context omitted.

explain?

shabble@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.

This technique fails if chmod is compiled statically.

Re: How do groups work on Linux?

#63
post #11
post #8

Earlier quoted context omitted.

While it’s nice to have it as default behavior when it makes sense, it’s also nice to have setgid as an option rather than the rule.

Nice or not, you can't talk about directory's SGID behaviour as it was unversal truth, because it's Linux-specific, and even then it's something that can be changed.

SunOS 4 definitely had this behavior, and I think it's even older than that — it probably goes back to 4.1bsd.

Re: How do groups work on Linux?

#64
post #49
post #43

Earlier quoted context omitted.

> If you were to demonstrate that it's universal I really wasn't. I was just making a point that it's not just Linux-specific like you claimed. In fact if you re-read the thread you'd realise that nobody argued this behaviour was universal. Given the breadth of POSIX-like systems out there, I doubt anyone would dare make such a bold statement. So you're arguing against point that was never raised. > And by the way, f…

>> If you were to demonstrate that it's universal > I really wasn't. I was just making a point that it's not just Linux-specific like you claimed. I never claimed it's Linux only , only that there are other systems with different semantics. >> And by the way, filesystems are typically implemented in kernel, so saying that it's not kernel that handles them is somewhat misguided. > Well yes file systems generally are,…

We are going round in circles so I'll have one last attempt to explain my point :)

> I never claimed it's Linux only, only that there are other systems with different semantics.

Maybe you shouldn't have said "Linux-specific" if you didn't mean it was specific to Linux.

Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system. I cannot comment about why your example didn't work the same. Perhaps you were using UFS instead of ZFS? Or non-default file system mount options / or other tweaks? Aside running ZFS as root and having compression enabled, my root zpool is pretty vanilla. But either way, it goes back to my point that this is a file system specific behavior not an OS-specific one.

> ...except that FUSE is in-kernel mechanism to delegate VFS callbacks to userspace program. It's hard to argue in such a case that the work is not the kernel's responsibility.

Your counterargument is just reiterating my point. File systems compiled against FUSE do not run in kernel space. The kernel syscalls obviously need to hook to your file system still (which is where the FUSE wrapper comes into play), but the FUSE API does all the user space / kernel space memory swapping so your actual FUSE file system doesn't run in the kernel.

This will obviously cause some extra overhead but with the exception of ntfs-3g, most file systems compiled against FUSE tend to be less performance-orientated anyway (eg they might be network bound). But as an aside note, this is also why I don't recommend people using ntfs-3g on low-footprint devices like the Raspberry Pi.

> Oh. This explains quite a bit, because I thought the argument was about whether the OS' usual semantics (group being inherited from directory or from EGID) are like that or not, not where in kernel this behaviour is coded.

> No, I'm making the case that Linux usually works one way, and BSD usually works the other way. I never claimed that anything was coded in any specific kernel subsystem, so don't add the statement yourself.

I know, I was the one that brought code into the debate. I did so very deliberately because software is code and you were making a point about the behavior of software. I'll I'm saying is that I don't agree with you that this behavior is OS-specific because the behavior is defined by the file system. Ie one file system could handle this behavior differently to another file system on the same OS by default. This is why I make a point about "where in the kernel the behavior is coded". It's not just an academic point, it's directly refuting the entire argument you've been having.

Anyhow, since your profile lists you as a developer as well as systems administrator - and you clearly do have a good understanding of the underlying architecture of BSD and Linux - I suggest you play around with a hobby file system yourself. It's good fun and FUSE is dead easy to learn as there will be bindings for most popular languages. I did mine in Go using an API that closely mirrors FUSE's C libraries but I've seen that most higher level languages (eg like Javascript) have FUSE bindings too - if that's your thing instead. Or obviously there's Rust and C/C++ if you prefer to work more directly with FUSE. You don't even need to work with hardware since you could just wrap FUSE around MySQL queries (as one of my latest experiments does) or even contents described in an ASCII file (as my first project did). Because Linux / BSD / whatever doesn't handle the actually writing of the file system (and why would it?), it means it's up to the file system to implement whatever set of behaviors surrounding permissions it wants.

Re: How do groups work on Linux?

#65
post #64
post #49

Earlier quoted context omitted.

>> If you were to demonstrate that it's universal > I really wasn't. I was just making a point that it's not just Linux-specific like you claimed. I never claimed it's Linux only , only that there are other systems with different semantics. >> And by the way, filesystems are typically implemented in kernel, so saying that it's not kernel that handles them is somewhat misguided. > Well yes file systems generally are,…

We are going round in circles so I'll have one last attempt to explain my point :) > I never claimed it's Linux only, only that there are other systems with different semantics. Maybe you shouldn't have said "Linux-specific" if you didn't mean it was specific to Linux. Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system. I cannot comment about why your example didn't work the same. Perhaps y…

> Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system.

No, you didn't. You attempted that, but you failed miserably by not including the most important piece of information: primary group of your shell.

> Perhaps you were using UFS instead of ZFS? Or non-default file system mount options / or other tweaks?

No, it was ZFS, as I stated clearly elsewhere. No options from me whatsoever. Now try the experiment with creating files again, but this time check your process' EGID. It may turn out that your interpretation of your own output was wrong.

> I'll I'm saying is that I don't agree with you that this behavior is OS-specific because the behavior is defined by the file system.

Being defined by a filesystem handling code and being the usual behaviour under particular OS are not the same thing.

Your claim boils down to disagreeing that it's the most prevalent behaviour for the OS, and you justify your position with the behaviour being coded in particular place, no matter that most of the other places for a given OS work in the same way. This is silly stance.

> I suggest you play around with a hobby file system yourself.

And this exercise would give me what, assuming that I haven't implemented a filesystem already?

Re: How do groups work on Linux?

#66
post #65
post #64

Earlier quoted context omitted.

We are going round in circles so I'll have one last attempt to explain my point :) > I never claimed it's Linux only, only that there are other systems with different semantics. Maybe you shouldn't have said "Linux-specific" if you didn't mean it was specific to Linux. Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system. I cannot comment about why your example didn't work the same. Perhaps y…

> Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system. No, you didn't. You attempted that, but you failed miserably by not including the most important piece of information: primary group of your shell. > Perhaps you were using UFS instead of ZFS? Or non-default file system mount options / or other tweaks? No, it was ZFS, as I stated clearly elsewhere. No options from me whatsoever. Now try…

> No, you didn't. You attempted that, but you failed miserably by not including the most important piece of information: primary group of your shell.

I did check that but must have missed it off the post. Sorry about that.

> Being defined by a filesystem handling code and being the usual behaviour under particular OS are not the same thing.

That was my whole bloody point! Glad you finally agree with me. It's the file systems that define that behavior so it's file system-specific not OS-specific (nor Linux-specific) like you previously claimed.

> Your claim boils down to disagreeing that it's the most prevalent behaviour for the OS, and you justify your position with the behaviour being coded in particular place, no matter that most of the other places for a given OS work in the same way. This is silly stance.

No, my point was that it's a file system-specific behavior not an OS-specific behavior. A point you then tried to pass off as your own (above) despite me categorically stating - numerous times throughout the discourse - exactly what my position is. Honestly I think this argument for you is less about facts and more about gradually moving the goal posts so you don't appear wrong.

> And this exercise would give me what

A greater understanding of a topic you've been happy to engage in arguments about yet reluctant to listen to other peoples feedback on. You're clearly an intelligent guy so if you're not going to take the experience of your peers into account (and I cannot blame you for wanting to trust your own experiences) then why not research this topic properly instead?

> assuming that I haven't implemented a filesystem already?

It's a bit late in the discussion to be playing the bluff card. :P

Re: How do groups work on Linux?

#67
post #19
post #18

Earlier quoted context omitted.

Except it does work FreeBSD: [lau@primus ~/test]$ mkdir setgid nosetgid [root@primus /home/lau/test]# chmod g+s setgid [root@primus /home/lau/test]# chgrp lau setgid [lau@primus ~/test]$ ls -l total 1 drwxr-xr-x 2 lau users 4 21 Nov 14:52 nosetgid drwxr-sr-x 2 lau lau 4 21 Nov 14:51 setgid [lau@primus ~/test]$ touch {nosetgid,setgid}/test [lau@primus ~/test]$ ls -l * nosetgid: total 1 -rw-r--r-- 1 lau users 0 21 Nov…

> Except it does work FreeBSD: Congratulations, you have an incomplete example. And what exactly did you want to prove? That an OS-specific behaviour can be exhibited by more than one OS?

Congratulations, you're passive-aggressive here without any reason to be.

Explains the downvote flood pretty well.

Re: How do groups work on Linux?

#68
post #66
post #65

Earlier quoted context omitted.

> Also I demonstrated that FreeBSD + ZFS behaves the same as Linux on my system. No, you didn't. You attempted that, but you failed miserably by not including the most important piece of information: primary group of your shell. > Perhaps you were using UFS instead of ZFS? Or non-default file system mount options / or other tweaks? No, it was ZFS, as I stated clearly elsewhere. No options from me whatsoever. Now try…

> No, you didn't. You attempted that, but you failed miserably by not including the most important piece of information: primary group of your shell. I did check that but must have missed it off the post. Sorry about that. > Being defined by a filesystem handling code and being the usual behaviour under particular OS are not the same thing. That was my whole bloody point! Glad you finally agree with me. It's the file…

Dude, my whole point revolves around the fact that the most prevalent behaviour for a given OS is OS-specific, which is a fucking tautology. What kind of feedback you expect me to accept from somebody who tries to make me believe the tautology is false?

Not to mention that the somebody tries to imply that I don't have enough knowledge about topic I'm quite sure I have, without ever pointing any error on my side, beside the tautology thing above.

Post reply on HN