Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have two computers: home and work. I have set these up pretty similarly (although home is Linux Mint 13 and work is Ubuntu 11.10). Assume my account name at work is "me_work" and my account name at home is "me_home".

I use a USB drive to share files from one computer to the other. I have written a script which mounts different directories of that drive to different directories on each system. For example, I do something like:

mount --bind /media/USB/MyProject $HOME/Projects/MyProject

As I work, on either computer, I do stuff in $HOME/Projects and this all gets saved on the USB drive. If I swap the USB drive out from one computer to the other, the files are all still there.

But there's a problem.

If I create a file while on my work computer it will be owned by the user "me_work" and the associated group "me_work". If I try to play with that file on my home computer I fail b/c I don't have permission to modify them. Furthermore, the "me_work" user or group are not known on my home computer.

Now, I could just sudo into everything, but I'm not always using a terminal - sometimes I'm doing stuff on a webserver, sometimes I'm using an IDE, etc.

How can I set things up so that the contents of the USB drive are readable by both my accounts? I have tried adding a new group to both computers called "me_usb" and setting both accounts to be members of that group. Then setting the gid of the directories on the USB to "me_usb" and making them group-writable. Unfortunately, that had no effect.

share|improve this question

migrated from Nov 7 '12 at 8:45

This question came from our site for professional and enthusiast programmers.

use nfs or sshfs... – anishsane Nov 7 '12 at 5:01
up vote 0 down vote accepted

Assuming that the goal is to have an identical copy of your Projects folder in the two locations specified, I must that there are cleaner ways to go about it.

The solution, using the methodology you expressed, is dependent upon the file system type of the USB drive's partition mounted at /media/USB and the mount options that were used.
Also, note that the possible permission data(uid and gid) stored on the file system is a numeric value(say 1000 or 1001) that corresponds to the user and group names(me_work, me_home, me_usb, ...). So, assuming the mounting operation is identical on both yours systems, if both me_work and me_home have the same uid value(first user added is usually 1000) the files will appear to be owned by me_work or me_home when used on your work or home system, respectively.

To show current mount parameters for /dev/USB issue the following command in a terminal:

mount | grep /media/USB

To show your user's current uid and gid's issue the following command in a terminal:


Now, I'll explain what is needed for the following common file systems:

fat32/vfat: We can force all files on the USB drive to appear to be owned by the user on the respective system. To do this, you need to have the mount options rw, uid, and gid set when mounting /media/USB.
To set these options after mounting /media/USB but before binding issue the following command as root:

mount -o remount,rw,uid=`id -u`,gid=`id -g` /media/USB

ext4 or ext3: You should be able to use the common group me_usb approach if it has the same gid value on both systems. After creating the group me_usb, you can change it's gid on each system by editing it's entry in the file /etc/group. It's entry should look similar to the following:

me_usb:x:<gid-number>:<me_work or me_home>

Alternatively, you can use a software called bindfs to replace the "mount --bind" step. Similar to the uid and gid mapping in the fat32/vfat section, bindfs can mount the USB disk file system elsewhere using different permissions. It is explained in a post on here.

share|improve this answer

The name of the user/group is irrelevant; what matters is the number.

Here's my entry in my /etc/passwd:


This says that my userid is 1009 and my (primary) group is group number 1000 (the second 1000). Looking now at /etc/group, I see:


This indicates that user-id rici is also a member of the adm group, group number 4, as well as there being a group rici with number 1000.

When I create a file, it's recorded in the filesystem as belonging to user number 1009 and group number 1000. That's the only information in the filesystem. System utilities use the /etc/group and /etc/passwd files to translate the numbers into friendly alphabetic labels.

If you want to synchronize between two computers, you have to ensure that the user and group numbers are the same on both machines. That's difficult once you have a lot of files, because while you can change the number your userid is translated into, you'd have to chown every file on the system to record the number user number. However, it should be fairly straightforward to create a new group on your home machine which has the same number as some group on your work machine, and then use that group as the owner for all shared files.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .