That's the problem with multi-user systems, especially if you have more than one of them. ;) There's no really nice way to do what you want. Approaches coming to mind would be
- having the same UID for your account on every machine you're using your external drive (actually not feasible, since most probably not all of the machines are under your control)
- using a file-system unaware of owner/group conecpt (FAT or NTFS coming to mind, but… aaah, no)
The most effective approach would be coming back to common practices. On most (at least) Linux systems, there exist some groups which have usually common GIDs. On example would be users
, which has GID 100
on most Linux distros. If you could manage to have your respective user account in this group, you could
- make all files and directories on your drive owned by this group
- somehow manage to have appropriate group-permissions on those files and directories
- somehow manage to have new files created with appropriate group-ownership resp. permissions.
First and second point are easy to accomplish (chown
, chmod
). Third point get's a bit trickier.
The "group-ownership" part is relatively easy: You could set the SGID bit on all directories on the drive. The SGID bit applied to directories tells the kernel to behave in a BSDish way: BSD makes every file/directory created under a specific directory group-owned not by the primary group of the process creating the file/directory (as Linux does), but by the owner of the parent-directory.
The permission bit is a bit hard. Permissions of newly created files/directories are (amongst others) influenced by the umask
, a bit-mask telling which bits not to set if not explicitly stated. A common umask
value for example is 022
, meaning that the write-bits for »group« and »others« shouldn't usually be set. You could change your umask
to 002
, telling you don't want the write-permissions to be cleared for the group but the downside is that you can't set this value directory-based and you usually don't want to have write-permissions for your primary group set for every file you create.
This could be solved using ACLs: In an ACL you can set a mask
and a default
permission set, which applies to all files and directories created inside a directory with this ACL set. So one possible solution of your problem would be
- making sure you are a member of a common group on all systems you want to use your external drive on
- make all files and directories on your drive owned by this group and set the SGID bit on all directories
- change the ACL of all directories to include a mask and default permissions that tell the kernel to create every new file/directory with write-permissions set for the group.
See setfacl(1)
, and acl(5)
for more details.