Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

5.10. Sharing Files Using Groups

Problem

Two or more users want to share files, both with write privileges.

Solution

Create a group containing only those users, say, smith, jones, and ling:

               /etc/group:
friends:x:200:smith,jones,ling

Create the shared file in a directory writable by this group:

jones$ cd
jones$ mkdir share
jones$ chmod 2770 share
jones$ chgrp friends share
jones$ ls -ld share
drwxrws---    2 jones   friends    4096 Apr 18 20:17 share/
jones$ cd share
jones$ touch myfile
jones$ chmod 660 myfile
jones$ ls -l myfile
-rw-rw----    1 jones   friends       0 Apr 18 20:18 myfile

Users smith and ling can now enter the directory and modify jones’s file:

smith$ cd ~jones/share
smith$ emacs myfile

Discussion

smith, jones, and ling should consider setting their umasks so files they create are group writable, e.g.:

$ umask 007
$ touch newfile
$ ls -l newfile
-rw-rw----    1 smith         0 Jul 17 23:09 newfile

The setgid bit on the directory (indicated by mode 2000 for chmod, or “s” in the output from ls -l) means that newly created files in the directory will be assigned the group of the directory. The applies to newly created subdirectories as well.

To enable this behavior for an entire filesystem, use the grpid mount option. This option can appear on the command line:

# mount -o grpid ...

or in /etc/fstab :

/dev/hdd3   /home   ext2    rw,grpid    1 2

See Also

group(5), chmod(1), chgrp(1), umask(1).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page