Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Two different users groups? Users can read eachothers files?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Sat Feb 12, 2005 2:07 am    Post subject: Two different users groups? Users can read eachothers files? Reply with quote

I asked someone in #gentoo on freenode: How do i add a user? His answer:
Code:
# useradd -m -G users username


So i did that for 2 users, user1 and user2..
Code:
# useradd -m -G users user1
# useradd -m -G users user2


But then i looked at the /etc/default/useradd file, and it had a default value:
Code:
GROUP=100


So i thought, *hey, -G users isn't nessecairy..* and i added user3 and user4, without the -G users:
Code:
# useradd -m user3
# useradd -m user4


Then i looked at the file /etc/group, and discovered that only the first two users, which i added with the -G users option, where member of the users group in that file:
Code:
users::100:user1,user2


Then i did an ID check on user1, and user3 to see the difference here..
Code:
# id user1
uid=1000(user1) gid=100(users) groups=100(users)
# id user3
uid=1004(user3) gid=100(users) groups=100(users)


Am i on crack or what is wrong here? Can someone please explain me what the meaning is of all this? And should i use the -G users or not?

Then i came to problem 2..

The users on the server, can all see eachothers files.. but not only see them, they can read them too! For example: user3 opens /home/user1/private.txt:
Code:
user3@server ~ $ vim /home/user1/private.txt

This is private information, and should only be readable by me, user1!
~
:q!


I ask someone again in #gentoo, and he answers: "Chmod them 700 or umask 077".

How nice.. now the websites in the public_html dir are unable to be viewed! What now?



Please, aswer both these questions.. i really don't know what to do anymore about it.
Back to top
View user's profile Send private message
transient
l33t
l33t


Joined: 13 Jan 2005
Posts: 759

PostPosted: Sat Feb 12, 2005 2:20 am    Post subject: Reply with quote

What the -G does is to specify what groups a user belongs to.
However, a user has one group that is their GID, which in this case is the default 100. The reason the other 2 users arent showing up in the groups file is because you never said for them to be members of that group

[edit]Sorry Ill try and make that post make sense....
A user has an initial group that they belong to. This is their main group, and its what the GID refers to. However, a user can also be a member of other groups as well. Those extra groups are what are listed in the /etc/groups file. You should use the -G option for creating users, as you will probably want them to be in the audio, portage, wheel groups for example.[/edit]


Last edited by transient on Sat Feb 12, 2005 2:27 am; edited 1 time in total
Back to top
View user's profile Send private message
donjuan
l33t
l33t


Joined: 11 May 2004
Posts: 760
Location: At Uni

PostPosted: Sat Feb 12, 2005 2:24 am    Post subject: Reply with quote

I don't know what the difference is with the -G option for the first group, but it looks like if you want to add the user to additional groups you need to use it.

He would be correct about the chmod thing. When I want to allow people to view my public_html files at school I have to change the permissions on that directory myself. So just do an extra chmod on that directory.
_________________
Command-line ACCEPT_KEYWORDS is considered harmful, use the package.* files.

The Stage 1 on 3 Install


Last edited by donjuan on Sat Feb 12, 2005 2:25 am; edited 1 time in total
Back to top
View user's profile Send private message
justanothergentoofanatic
Guru
Guru


Joined: 29 Feb 2004
Posts: 337

PostPosted: Sat Feb 12, 2005 2:24 am    Post subject: Reply with quote

UNIX allows users to belong to more than one group. However, one group must be designated as the 'primary' group. The primary gid is stored in /etc/passwd and determines, among other things, the default gid for newly created files (files, unlike users, belong to only one group).

So, if the user belongs to only one group, his primary gid is stored in /etc/passwd, and there is no need for an /etc/groups entry. Unfortunately, each /etc/passwd entry can contain only one gid. If the user belongs to any 'secondary' groups, they need to be entered in /etc/groups.

Placing a 'primary' gid entry into /etc/groups is redundant, since the system already reads the group from /etc/passwd. But it doesn't do any harm.

Quote:
And should i use the -G users or not?

As you can see from the above, it doesn't make much difference. Using the -G option will ensure that primary groups are also stored in /etc/groups, which may help if you like to view all group memberships at a single glance.

Quote:
How nice.. now the websites in the public_html dir are unable to be viewed! What now?

Well, it is called "public" for a reason. =) Those files need to be publicly viewable so the web server can read them.

-Mike


Last edited by justanothergentoofanatic on Sat Feb 12, 2005 2:37 am; edited 1 time in total
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Sat Feb 12, 2005 2:33 am    Post subject: Reply with quote

Problem 2: Maybe if someone explained how permissions worked, you'd understand what happened and why someone on #freenode suggested "chmod 700" or "umask 077".

4 = read
2 = write
1 = execute

The combination of the above gives your files/folders the permission you desire. And if you are a bit creative you might have guessed that umask is the total opposite of chmod! For chmod "7" means give all 3 of r,w,x permissions while for umask it means DO NOT give those permissions. When you set permissions you set them for either (or all 3) of USER, GROUP and OTHERS. Saying "chmod 700" is like "USER has all permissions" while "GROUP" & "OTHERS" have squat. This explains why public_html is in-accessible now. You may leave all other files/folders in your home directory with permissions of "chmod 700" but change them for public_html. Something like "chmod 755" for public_html will be suitable for it.

I know I am not good at explaining things to people but I hope that helped. Problem 1 is beyond me at the moment.

Edit: Ok you guys up there, stop beating me to answering this post T_T
Back to top
View user's profile Send private message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Sat Feb 12, 2005 2:46 am    Post subject: Reply with quote

dhalsiim wrote:
And if you are a bit creative you might have guessed that umask is the total opposite of chmod!

Serious? Cause actually they only said chmod 700, i wrote the umask 077 there myself cause i do know how it works.

Anyway.. so far Problem 1 is explained, thanks very very much justanothergentoofanatic and transient :)

But now problem 2..

It's a webserver.. people don't want lycos banners, and don't wanna pay for having a website hosted.. for me, building a webserver is fun, it interests me (though Debian really wasn't as interesting as Gentoo).. and it isn't there for nothing, so i let them have an account.

But, those people think CHMOD is outer-space language, they never heard of it. Is there a way to do this automaticly or in another or certain way? For the record, i'm using vsftpd.. maybe i can do a little magic with that one? Though i rather have another solution, cause just a few users get shell access.. and if they decide to make that, for example private.txt, in the shell.. it's again readable by all users, and i don't see them chmodding every file they make everytime.

So, someone got a solution for this?

Thanks to all the people who helped me, and thanks in advance to the people who are going to help me with this.
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Sat Feb 12, 2005 3:04 am    Post subject: Reply with quote

I just assumed everyone's like me ><; when I first started using linux chmod was intimidating. I always tried to memorize the different combinations of 4+2+1 not knowing the underlying trickerky, let alone even knowing how umask worked. So yeah, they both are kinda like outerspace stuff for me ;)

umask is automatically set for files/folders from settings in /etc/profile. That would be one automatic way? Or if they get shell access, their .login files can be edited to hold that information! With ftpd's, I know that proFTPD has a umask module that allows such permissions to be set on newly uploaded files. Perhaps if you look into vsftpd's documentation you might find something similar?
Back to top
View user's profile Send private message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Sat Feb 12, 2005 3:14 am    Post subject: Reply with quote

Hmmm.. i can try it out.

So, give the files chmod 700 except for the contents of the public_html dir which should be 705?

I just remembered that on the Debian webserver i had before, users automaticly got their own group.. so if i created a user called nike (uid 1034 for example) they would automaticly get a group nike (gid 1034). Then i didn't have to go through all this trouble..

Why doesn't Gentoo do that automaticly? I find it strange that so many people find it normal to put all users in one group called users while it brings serious security issues with it if one didn't pay attention.. and i have the feeling there are a lot of people who didn't.
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Sat Feb 12, 2005 3:30 am    Post subject: Reply with quote

I am not sure if the middle 0 in 705 affects anything at all but you could give it a shot. Yes the contents of public_html set to that permission should make it work but public_html itself should have the "execute" permission for its contents to be able to be read.

And I never knew users automatically had their own group created on other distros.. that's new info. Good stuff XD
Back to top
View user's profile Send private message
transient
l33t
l33t


Joined: 13 Jan 2005
Posts: 759

PostPosted: Sat Feb 12, 2005 5:26 am    Post subject: Reply with quote

The umask is ANDed with the default file creation permissions to create the actual permissions you see.
The default permissions are 777 for directories, and 666 for files.
In the case of a directory, this is ANDed with the default umask's ones compliment (022) to give you the usual permissions of 755.
Although Im referring to the binary AND operation here, because of the way its setup, you can simply subtract the umask from the default permissions to get the actual permissions. No need to mess around with bit ANDing and so on :) Note that this method doesnt work for all situations, particularly when you are untarring a file
This also means that it is impossible to create a file that is executable. You always need to
Code:
chmod +x
it after creation, with the exception of compiled binary files.

[edit]Removed umask crap that was wrong[/edit]


Last edited by transient on Tue Feb 22, 2005 4:59 am; edited 3 times in total
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Sat Feb 12, 2005 6:09 am    Post subject: Reply with quote

The 700 and 705 in the post above yours is for chmod. But your insight on ANDing the bits is very informative. Thank you for sharing it.
Back to top
View user's profile Send private message
transient
l33t
l33t


Joined: 13 Jan 2005
Posts: 759

PostPosted: Sat Feb 12, 2005 6:20 am    Post subject: Reply with quote

Ah thanks, I misread the post :oops:
Back to top
View user's profile Send private message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Tue Feb 22, 2005 3:05 am    Post subject: Reply with quote

Isn't it a better idea to just give every user on my server it's own group, and remove it from group users? Or could that bring problems with it?
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Tue Feb 22, 2005 3:58 am    Post subject: Reply with quote

Bahaha.. last post: Sat Feb 12, 2005 12:20 am & latest post: Mon Feb 21, 2005 9:05 pm. I mean numbers turn me on but this is amazing. Feb 12 and Feb 21. Well I personally don't see anything wrong with that. But do you really want to trust a (11 months old) linux user? The thing is .. you might have to change all sorts of permissions left and right.. perhaps if you ask a forum mod or a developer you might get a better answer. I just answered this post to point out the face about the posting dates that's all. Sorry for any disappointment :S

Edit: geez.. I'm the worst typist ><; face = fact :D
Back to top
View user's profile Send private message
transient
l33t
l33t


Joined: 13 Jan 2005
Posts: 759

PostPosted: Tue Feb 22, 2005 5:02 am    Post subject: Reply with quote

dhalsiim wrote:
Bahaha.. last post: Sat Feb 12, 2005 12:20 am & latest post: Mon Feb 21, 2005 9:05 pm. I mean numbers turn me on but this is amazing. Feb 12 and Feb 21. Well I personally don't see anything wrong with that. But do you really want to trust a (11 months old) linux user? The thing is .. you might have to change all sorts of permissions left and right.. perhaps if you ask a forum mod or a developer you might get a better answer. I just answered this post to point out the face about the posting dates that's all. Sorry for any disappointment :S

Edit: geez.. I'm the worst typist ><; face = fact :D

Um...?
What are you talking about :S
Back to top
View user's profile Send private message
dhalsiim
Guru
Guru


Joined: 29 Jan 2003
Posts: 486

PostPosted: Tue Feb 22, 2005 5:36 am    Post subject: Reply with quote

It just made me giggle, the fact that the last post by you was on the 12th of this month. And the latest on the 21st. 12:21 .. I don't know, feels funny (awkward someone might say).
Back to top
View user's profile Send private message
j-m
Retired Dev
Retired Dev


Joined: 31 Oct 2004
Posts: 975

PostPosted: Tue Feb 22, 2005 7:53 am    Post subject: Reply with quote

lcidw wrote:
Isn't it a better idea to just give every user on my server it's own group, and remove it from group users? Or could that bring problems with it?


That´s what RedHat and Fedora does. Extremely annoying. Also, don´t set 0700 on users home directories, you won´t be able to list them, public_html won´t work with Apache, etc. etc. Use at least 0711.
Back to top
View user's profile Send private message
lcidw
Tux's lil' helper
Tux's lil' helper


Joined: 18 Oct 2004
Posts: 77

PostPosted: Fri Feb 25, 2005 8:58 pm    Post subject: Reply with quote

Quote:
Bahaha.. last post: Sat Feb 12, 2005 12:20 am & latest post: Mon Feb 21, 2005 9:05 pm. I mean numbers turn me on but this is amazing. Feb 12 and Feb 21.


What does the time between posts matter, it's simply a simpel but interesting security thread :)

Quote:
That´s what RedHat and Fedora does. Extremely annoying.


And why is that annoying?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum