Folder permissions

I get that in Linux drives are seen as folders. When I ran my initial setup, my second internal hard drive was formatted as ext4. It originally was owned by root, so I used chmod to change the ownership. But I still have to authenticate whenever I restart my system. Any ideas? Thanks for your help.

To confirm: Did you mean you used chown or chmod?

Chown. I have to learn a whole new language dealing with Linux. It’s been too long since I did much with the command line. Chown changes ownership and chmod does, what, exactly?

https://wiki.archlinux.org/title/File_permissions_and_attributes

2 Likes

chmod alters the accessibility mode… i.e., who can access and with which privileges. Whereas chown actually changes file/directory ownership itself.

Join the club. Many years at this and still learning all the time. :slight_smile:

2 Likes

Mount points are directories, if that is what you mean. Where is the device mounted?

What is the exact command you ran? Check history if you are not sure.

In what way are you trying to access the drive when it asks you to authenticate?

Along with @BluishHumility’s question above, I’m wondering if you’ve delved into fstab - used to bring this second external drive up and running when you boot up? This may have something to do with the behavior I think you’re describing in your OP.

https://wiki.archlinux.org/title/Fstab

The mount point for the folder is /run/media/rob/cd1b7001-5403-486c-bdc8-b65118f4aa20. It’s on device sda2, which is my second internal hard drive.

This was the exact command I ran:

sudo chown -R rob:rob /run/media/rob/cd1b7001-5403-486c-bdc8-b65118f4aa20

The history tip is useful, thank you for that.

It’s generally at startup after I shutdown, restart, or log out. It’s as if the permissions reset. I’ll have to do things like authenticate if I wantr to open the drive in a file manager or I’ll have to manually add the drive in steam to access what I have saved there.

I had to do some work in fstab in order to get Linux to see the drive. It’s my /sda2 device and I had to manually add the UUID and other settings to fstab in order to just see the drive. I then ran chown to give my user profile access to the drive as previously it was assigned to root. This went well. But now I have to authenticate with my password any time I want to access the drive after any kind of a shutdown even like logging out, restarting, etc.

Any chance you selected the encrypted option for your drive? I’ve never bothered to do this (being a home user, not in a shared environment setting) so I’ve got no direct experience to share, but perhaps this is contributing to your need to authenticate?

If so, here’s some info to get you started …

Probably you got this mount point by mounting the device with a GUI file manager or something like that. It is important to appreciate that the /run directory is a temporary filesystem, and its contents are cleared every time you shut down or reboot. The modifications you are making to the filesystem permissions for this mount point are also not persistent, so it makes sense that ownership is restored to root every time (because systemd is creating the mount point fresh at every boot to allow it to be mounted).

You can resolve this issue by using a different mount point. It doesn’t matter where it is, as long as your user has ownership of it. You can set it right in your home directory if you’d like.

mkdir -p ~/my_cool_mount_point

Adjust your /etc/fstab entry to use the new mount point instead of /run/media/rob/cd1b7001-5403-486c-bdc8-b65118f4aa20. After you save it, reload the systemd daemon.

sudo systemctl daemon-reload

Unmount the /run mount point.

sudo umount /run/media/rob/cd1b7001-5403-486c-bdc8-b65118f4aa20

Then mount again at the new mount point.

sudo mount /home/rob/my_cool_mount_point
1 Like

So far as I know I did not encrypt anything. That is a discrete action you have to take at install or deliberate do it in the terminal I believe after install. I’ve done neither so far. Install was enough of a challenge without setting that up. The odd part is that I have an external drive hooked up through USB 3.0 that doesn’t seem to give me the same issues as the internal drive.

That would make sense if the run directory is a temp one. Unfortunately I can’t find the command I used to get the mount information for the drive which set it to the /run directory. I found some guide on here and followed it. Ah well, lesson learned. At least things are starting to make sense and I’m getting a feel for how customizable Linux really is. Before I make these edits, any suggestions on best practices. The last thing I want is a rats nest of changes I made that I have a hard time going back and remembering what I did. I know there’s a mount directory and at first glance it would seem that would be the place to do all this. Your answer was very detailed and explained a lot. Thank you for that.

One additional question. I specifically used the UUID to mount the drive. Do I need to continue that when I use the mkdir command or can I use an alias like data. I understnad it’s bertter to use the UUID in fstab so links don’t get broken and such. Or do I need to mount the device exactly as written in fstab?

@BluishHumility FWIW, my fstab file includes mounting entries for two external partitions at /run/media/ejm/... and I never need to (re)authenticate upon boot up.

I use one partition on an external drive for Vorta/Borg incremental data backup and the other for Timeshift full system-only backup. The owner of Timeshift directory is root and the owner of the Vorta/Borg directory is ejm … as such it remains unclear to me whether ownership necessarily determines what’s happening with the OP’s issue.

No doubt you’ve already forgotten more about Linux than I’ll ever know, but are you sure? :man_shrugging:

After citing their respective UUIDs in fstab I then use their nickname labels for all my human interactions with them once my system has booted up.

Yeah i followed a helpful link @ejm provided and answered that question right after the edit. Configuring Linux is going to take some getting used to. UUID goes first, mount point second. Can you give any direction on mount options, dump, and pass? I can just follow a tutorial but it doesn’t help me understand the why, if you get my meaning.

No problem to use the /mnt directory if you wish, however bear in mind this directory is owned by root so you will need to use the chown command like you did earlier if you choose this method.

sudo mkdir /mnt/my_cool_mount_point
sudo chown -R rob:rob /mnt/my_cool_mount_point

Using /mnt instead of a user’s home directory could be a better option in certain use cases, for example if you wanted to set up a mount point which would be accessible to multiple users on the same computer.

Either way you go should be fine; once you get the hang of it, you will see it’s pretty easy to make changes later on if you decide to change your mind.

You do not need to use a UUID to mount a device if you have another way of identifying it. For example, if you run lsblk you can use the name of the device to mount it.

❯ lsblk
NAME          MAJ:MIN RM   SIZE TYPE 
nvme0n1       259:0    0 931.5G  disk  
├─nvme0n1p1   259:1    0    99M  part 
├─nvme0n1p2   259:2    0   7.4G  part 
└─nvme0n1p3   259:3    0 924.1G  part  

You can mount a device with mount /device/name /path/to/mount/point, so in my example here if I wanted to mount the second partition I can do it like this:

sudo mount /dev/nvme0n1p2 /mnt/my_cool_mount_point

For the fstab it is better to use UUIDs instead of the name of the block device because the names can change if you add or remove devices (for example, plugging in a USB stick may cause the names to be reordered).

For a device which has been added to fstab, it is enough to just use the path to the mount point.

sudo mount /mnt/my_cool_mount_point

Systemd will get the rest of the info from /etc/fstab.

Borg typically runs as root. For example, if it is being run on a systemd service that will be run as root.

Just to clarify: no mount point will require authentication unless a user which does not have permission is trying to access it. If you click on the Borg mount point in a GUI file explorer as an ordinary user, you may find it asks for authentication.

In general I would advise not using /run directories as permanent mount points, but I suppose if it is working for you then it is probably harmless.

1 Like

Thanks. Interesting info.

I usually use nnn as my file mgr but just checked using GUI nemo: Same results either way of accessing… Vorta/Borg backups are shown as owned by “ejm” and are readily editable. But Timeshift backups remain read-only for me without resorting to su privileges.

As for mounting in /run/media/ejm, I seem to recall having done this within fstab from the get-go. Haven’t encountered any known issues as a result. OTOH, when I screw up my EOS/Linux settings I tend to do it manually through other avenues. :wink:

How the permissions are handled in the /run directory depend on how the directories are created. If I plug in a USB stick and click on it in Thunar, it creates /run/media/jeremy/[device name] for me and gives my user ownership.

❯ eza -l /run/media/jeremy
drwxr-xr-x - jeremy 27 May 14:25 Ventoy

There is some behind-the-scenes magic at play here; I think it uses udisks2 to get it set up like this, with the permissions and all. By default, /run/media/jeremy does not exist.

If I create it manually, I do not get permission to directories in it by default. For example:

❯ sudo mkdir -p /run/media/jeremy/test

❯ eza -l /run/media/jeremy/
drwxr-xr-x - root 27 May 13:41 test

The test directory is owned by root. I will take ownership of it and reboot:

❯ sudo chown jeremy:jeremy /run/media/jeremy/test

❯ eza -l /run/media/jeremy/
drwxr-xr-x - jeremy 27 May 13:41 test

❯ reboot

After rebooting, the directories I made are gone–as if they never existed.

❯ eza -l /run/media/jeremy
"/run/media/jeremy": No such file or directory (os error 2)

If I make them again, the ownership is restored to root.

❯ sudo mkdir -p /run/media/jeremy/test

❯ eza -l /run/media/jeremy
drwxr-xr-x - root 27 May 14:23 test

@ejm if you have persistent directories in /run/media/ejm which are honoring your permissions, there is probably something else providing that configuration. Maybe udisks2, or some other disk management utility using a configuration you have set up somewhere. Unless you adjust the permissions with mount options, if you just add them in /etc/fstab then root should have ownership.

All that to say: probably it can be made to work, but a more straightforward way to mount a device in fstab with user access would be to use a mount point that is not in /run, and provide permission to the user or one of the user’s groups for the mount point.

1 Like

That did the trick. Thank you very much for you help and the insightful explanations.

1 Like