18

I have an external hard drive and since I only use Ubuntu and Fedora I decide to format my hard drive to ext4 everything is fine.

The problem is when I mount the drive I need to change the permission so I can read and write.

What kind of permission should I use? adm my user name?

5

Lame though it may be of me, I'm going to have to answer the question with another question. If all we're talking about is for one OS, then it would be either

sudo chown -R (user name) /dev/(device name)

(ubuntu)

or just

chown -R (user name) /dev/(device name)

fedora - no sudo, just run the command from root.

The noodle scratcher part, and the part I don't have any good answers for, is how to make it so you don't have to manually retype when you go back and forth between distros. I'd almost be tempted to add the line to my ~/.bashrc, but there's probably a better way I don't know or haven't thought of yet.

4
  • That what i tho i need to change the permission every time i change of distro – Javier Gonzalez Nov 8 '10 at 0:42
  • 1
    Just to make sure and satisfy my own intellectual curiousity, I went back and double checked with a USB EXT4 drive I have. I didn't know if taking ownership of the device is the same thing as taking ownership of the filesystem, and it is. sudo chown -R (user name) /dev/(device name) gets you ownership of all the files on the drive, even if you didn't create them. – user2367 Nov 8 '10 at 0:44
  • Yeah, short of just adding the line to ~/.bashrc so it runs automatically every time you run terminal, I don't have an answer to that. Maybe could add it to cron? But it seems like there should just be a way to arrange for it to run when the distro boots. – user2367 Nov 8 '10 at 0:46
  • I really love ext4 but is a crap keep changing the permission haha – Javier Gonzalez Nov 8 '10 at 0:49
10

The simplest solution is to make sure your Ubuntu & Fedora user accounts have the same user id (UID).

I think Fedora starts user accounts at 500 by default, while Debian & Ubuntu start them at 1000, so it's very likely that in one OS you are user number 500 and in the other you are user number 1000. The file system uses this UID number to keep track of permissions, so if you make sure they have the same UID, they will be considered the same user, and no permission issues will happen.

I think the best you can do is make them both UID = 1000, so change the UID in the Fedora system, then make sure all files on the external disk and in the user's $HOME in the Fedora install are owned by UID 1000. After that you should have no permission problems anymore.

3
  • Yeah i gonna do that thank you for your time :) – Javier Gonzalez Nov 8 '10 at 0:58
  • 1
    Please also read my addition or the Fedora user will not be able to log in! – JanC Nov 8 '10 at 1:03
  • Everything is clear i gonna test it right now, also thanks for edit the question title now is very clear. – Javier Gonzalez Nov 8 '10 at 1:07
3

In /etc/fstab you could put uid=1000 (in Ubuntu -- it's 500 in Fedora) for the drive to be owned by your user (assuming you're the first user, yada yada yada... if not, your user's uid from id) and umask=000 if you wanted all users to have access (or 077 for just the one specified by uid= -- it's a mask, so you put the opposite of what you'd chmod as)

For more info on using /etc/fstab: http://ubuntulinuxtipstricks.blogspot.com/2008/02/fun-with-etcfstab.html

2
  • 1
    If i set the permission to 077 i don't need to re change the permission when i change from ubuntu to fedora? – Javier Gonzalez Nov 8 '10 at 0:43
  • @Dracirate: I think you might need 000 rather than 077. If you put an fstab entry for the drive in each system (both Ubuntu and Fedora), they will automatically mount it so that it's usable. – maco Nov 8 '10 at 7:24
3

Unfortunately Linux kernel enforces POSIX permission on ext2/ext3/ext4 FS.

You may workaround POSIX permission with shared group. I ask corresponding question: https://unix.stackexchange.com/questions/273144/predefined-group-ids-across-linux-distros/ but after all I made own research.

I discover that sys group share id 3 on Debian, Ubuntu, RedHat, Fedora, CentOS, Suse, FreeBSD, OpenBSD, NetBSD, MacOSX, Solaris.

With such discover in mind one solution may look like:

$ sudo chgrp -R sys /mnt/data/dir
$ sudo chgmod -R g+s /mnt/data/dir
$ sudo fsetacl -R -m g:sys:rwx /mnt/data/dir
$ sudo fsetacl -R -d -m g:sys:rwx /mnt/data/dir

and flavor of this (whenever you on Linux/FreeBSD/MacOSX/Solaris):

$ sudo adduser user sys

See also:

1
  • Using that method, executing cd /mnt/data/dir; touch example.txt; ls example.txt ... shows ... -rw-rw----+ 1 user user 3 nov 27 20:16 example.txt. Executing later mv example.txt ~; ll ~/example.txt ... shows ... -rw-rw----+ 1 user user 0 nov 27 21:22 /home/user/example.txt, with that + at the end of the permissions. So a lot of + are going to end up appearing in a lot of places, making people wonder why those files are special (just because they happened to be copied/moved from a particular folder). Is there any way to stop producing those + automatically? – Ganton Nov 27 '19 at 21:18
3

This is a slight variation of @gavenkoa's approach of using shared groups, and does not involve modification of the mounted drive.

Check what group id (GID) is used in the mounted drive.

su
cd /mnt/data/dir  # or wherever it is mounted
ls -l

Let us say you see something similar to the following:

drwxr-xr-x 3 12588 12000  4096 30.06.2017 11:22 Documents/

This means 12000 is the current GID of the data in the drive, and the data can be read, and executed (cannot be written, though) by any other user of the group. Create a new group (for eg. driveusers) and add your current user to the new group:

groupadd -g 12000 driveusers
sudo gpasswd -a $USER driveusers  # add the current user to the new group
sudo chmod 770 /mnt/data/dir      # optional, just to ensure the drive mount is accessible to user and group of the drive
2

You could just try to use exfat or ntfs. For me it works this way. But i don't now if it works with every file permission. I think not.

2

I found this other solutions:

https://unix.stackexchange.com/questions/422656/how-to-make-an-ext4-formatted-usb-drive-with-full-rw-permissions-for-any-linux-m/468933#468933

https://unix.stackexchange.com/a/273705

With this:

sudo chgrp -R sys /mnt/data/dir
sudo chmod -R g+s /mnt/data/dir
sudo setfacl -R -m g:sys:rwx /mnt/data/dir
sudo setfacl -R -d -m g:sys:rwx /mnt/data/dir

and flavor of this:

sudo adduser user sys  

your user be able to read/write any file on /dir.

@jadelord @ gavenkoa do you please think there's any improvement that could be done nowadays on your suggested solutions for Ubuntu (or Fedora) users? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.