sexta-feira, agosto 24, 2012

Linux Tutorial: How to Create a Shared Area

One problem I always had with me and my wife using the same computer was that sometimes we need to share things that are family related like photos, videos and stuff.

So on Linux, what do you do?

In my case, I created a commom user e.g. media. I also changed the user to not allow it to login because I don't need that (and because I can :)).

# cat /etc/passwd

# ls -l /home
drwx--x--x  83 media     users    12288 Ago 24 11:39 media

To make it fancy, I also created a group for that user and added me and wife to it.

# cat /etc/group

# cat /etc/passwd

# ls -l /home
drwx--x--x  83 media     media    12288 Ago 24 11:39 media

This was enough for me and my wife to start to share files, but we had another problem. Every time me or my wife moved a file there, the other one couldn't move the file around - like to categorize the photos inside subdirectories.

Another problem, all files we moved there continue with our user group and as I created an specific group for that I wanted to have it in that group (ok, not a problem, but oh boy, I want it).

To make files created on that directory to belong to media group was the easy one:

# chmod -R g+rws /home/media

Did you notice the 's' at the end of group permissions change? That does the trick of making sure that all files moved to that directory is going to be changed to the directory group instead of the users's group.

To solve the problem of me and my wife changing files the other one created on that directory I had to cry for help from ACL.

I won't explain what ACL is or isn't, so if you want more information about it, please google it. I'll just show you how I set it up.

First thing you need to mount your filesystem with ACL option enabled, then you can set the default permissions for an specific directory.

# cat /etc/fstab
/dev/sdb1 /home ext3 defaults,acl 0 1

# setfacl -R -dm g::rw /home/media

That's all. Enjoy!

Nenhum comentário: