# Creating a folder all users can use

## TheHood

I have a PC with two users on it, james and rachel.  Obviously each have home folders.  What I want is a something like a "shared home folder" as well, i.e. somewhere where each user can bung files / folders, and where all things in that folder have read/write permissions for BOTH users, regardless of who created them.  

I thought (haha) this would be simple, so here's what I did:

1) create a folder /home/share/

2) chgrp -hR users share/

So far so good, all files get created with "users" as group.  But the problem is, all files get created with 644 permissions, so if james creates the file, rachel can't edit and save it.  So I need get it so that the default group permissions of the files are 664 not 644 - how do I do this?

I tried using umask 002, and discovered this needs to go in /etc/profile, ~/.bashrc and ~/.bash_profile so I put it in all 3 of these.  The thing is, files are still getting created with 644 permissions.  ARGH! Can anyone help (or offer a better solution to the one I'm trying)?

----------

## i92guboj

I guess that you could use vfat, which doesn't store permissions. They are emulated at mount time instead, so that should work.

----------

## forkbomb

Maybe the SGID bit?

chown users /parent/directory/to/share

chmod -R 2xyz /parent/directory/to/share

This claims it should work (but I haven't tried it):

http://www.livefirelabs.com/unix_tip_trick_shell_script/sept_2003/09152003.htm

The problem with why james can't edit rachel's file and vice versa is that when james creates a file, the file is associated with the "james" single user group.

----------

## TheHood

@forkbomb:

No, step 2 already sets SGID and all files in the directory are created with the "users" group, which james and rachel are both members of.  That bit works fine.

The problem is that files are created with -rw-r--r--, so group members don't have write permissions.  I want it to be -rw-rw-r-- by default.  How can I make every file get created with these permissions instead?

----------

## ppurka

Does umask 002 in /etc/profile work?

----------

## Nerevar

It sounds like for whatever reason the users umask isn't getting set properly. Run umask w/o args as the user to see the current value.

----------

## ppurka

Yeah. Modify /etc/login.defs instead.

----------

## forkbomb

 *TheHood wrote:*   

> @forkbomb:
> 
> No, step 2 already sets SGID and all files in the directory are created with the "users" group, which james and rachel are both members of.  That bit works fine.
> 
> The problem is that files are created with -rw-r--r--, so group members don't have write permissions.  I want it to be -rw-rw-r-- by default.  How can I make every file get created with these permissions instead?

 

By "step two", you mean chgrp -hR? I don't particularly understand the -h switch but chgrp shouldn't be touching the SGID bit (only chmod can set sticky bits). Just for the sake of argument I made a dir and ran these commands until I saw the SGID change:

```

# mkdir foo

# ls -l

total 4.0K

drwxr-xr-x 2 root root 4.0K May 31 17:07 foo

# chgrp -hR portage foo

# ls -l

total 4.0K

drwxr-xr-x 2 root portage 4.0K May 31 17:07 foo

# chmod 2755 foo

# ls -l

total 4.0K

drwxr-sr-x 2 root portage 4.0K May 31 17:07 foo

```

As to why files are being created with those permissions, that seems a different bit, but I doubt your SGID bit is set unless you've specifically set it with chown.

Also, I tested it the way you did it, and compared it to doing chmod 2xyz, and the files made inside of the parent directory will not inherit the parent directory's group unless you set the SGID bit (which chgrp will not do). If file inside your /home/share directory are being created with a users association, their primary group is probably already users (try ls -l /home/rachel/). My normal user's primary group is the single user group and here's what happens (using /tmp/home/share instead). Even though I set the parent directory to the users directory, when I created a file it was not associated with the parent's group but with my normal user's default group (SUG):

```

# mkdir /tmp/home

# mkdir /tmp/home/share

# chgrp -hR users /tmp/home/share/

# chmod 777 /tmp/home/share/

# logout

$ cd /tmp/home/share

$ touch foobar

$ ls -l

total 0

-rw-r--r-- 1 tjvanwyk tjvanwyk 0 May 31 17:25 foobar

```

All that said, the issue is with that funky default create perm you're seeing.

----------

## TheHood

@forkbomb:

Sorry you are right.  I forgot to include the chown u+s command I used.

@ppurka:

That seems to have done the trick - thanks  :Smile: 

----------

## forkbomb

 *TheHood wrote:*   

> @forkbomb:
> 
> Sorry you are right.  I forgot to include the chown u+s command I used.
> 
> 

 

Oh, not a problem. Just had me confused for a second there.  :Smile:  (Hence the multiple edits I made as I double checked the behavior of the SGID bit to make sure I wasn't talking like a moron.)

----------

