Date Category tech

I have a pretty awesome little network storage drive made by Synology that I use for backups, large media files, and anything I may want to access across more than one computer. It has one unfortunate limitation: by default, my uid (user id) is 1026, and I can’t change it to anything below 1024 without causing problems. (discussion here)

Of course, my uid on most of my computers is 1000, the default for Debian-based Linux systems and probably many others. NFS operates on raw user ids (e.g. 1026) rather than user names (e.g. mike), which essentially requires these uids to line up on all your computers. The “correct” solution would be to change my uid on every OS I run to 1026 (what a hassle), possibly by using an LDAP server to host user accounts (total overkill for a small home network). Isn’t there some hacky solution, perhaps involving duct tape and zip ties?

It turns out there is: bindfs, a FUSE-based filesystem that supports a bunch of permissions and ownership tweaks and transformations.

The feature I care about is uid mapping, but check out the bindfs site for other uses.

Example session:

$ mkdir mike mike_fixed
$ sudo mount -t nfs nas:/volume1/mike mike
$ ls -l mike/hello.txt
-rw-r--r-- 20 1026 mike  4096 May 27  2013 hello.txt
$ touch mike/hello.txt
touch: cannot touch `hello.txt': Permission denied
$ sudo bindfs --map=1026/1000 mike mike_fixed
$ ls -l mike_fixed/hello.txt
-rw-r--r-- 20 mike mike  4096 May 27  2013 hello.txt
$ touch mike_fixed/hello.txt
(touch silently succeeds)

Notice how the file now appears owned by ‘mike’, who has uid 1000 on my local system. From now on, I can treat files on that bound filesystem as if they’re owned by me without any permissions headaches! (Also note that the gid (group id) already matched, but bindfs also supports mapping groups if this is needed.)