Mounting filesystem with special user id set
Solution 1:
bindfs
is the answer. It will take an already mounted file system and provide a view of it with whichever uid you'd like:
sudo apt-get install bindfs
mkdir ~/myUIDdiskFoo
sudo bindfs -u $(id -u) -g $(id -g) /media/diskFoo ~/myUIDdiskFoo
Solution 2:
It's not possible to force an owner on a disk with an ext4 filesystem. Only filesystems which do not support Linux permissions like fat have an attribute for ownership/groupship: uid=value
and gid=value
. See the manual page on mount.
You should change the owner on the mounted filesystem as in:
sudo chown johndoe /foo/bar/baz
If you need to change the permissions recursively:
sudo chown -R johndoe /foo/bar/baz
...and if the group needs to be changed to johndoe
as well:
sudo chown -R johndoe: /foo/bar/baz
Solution 3:
Assuming the group set for the files has appropriate permissions, you should be able to just find out it's Group ID (GID) and add yourself to it.
To find out the group id of a file, use ls -n
. Example output:
drwxr-xr-x 1 1000 1000 550 Jul 9 11:08 Desktop/
You want the fourth field for GID, which in my case is the second 1000
.
sudo addgroup --gid GID foobar; sudo usermod `whoami` -aG foobar
Once you run that you should have full rein where ever the file attributes for group allow it.
As noted in the other answer relating to user permissions, if you need to fix the group on some files, run one of these:
sudo chown -R :foobar ./
sudo chgrp -R foobar ./