Changing ownership after mounting ext4 filesystem at boot time
Changing ownership after mounting filesystem at boot time.
I have the following Code:
/dev/sda5 Code:
/dev/sda5 /mnt/tempdir ext4 defaults,noexec 0 0 If I do a remount or a reboot, /mnt/tempdir is owned by root: Code:
sudo mount -o remount /mnt/tempdir Obviously this is possible since each user's directory is owned by the user at boot time. NOTEs: For filesystem type ext4, adding uid=<user_id> to fstab is not allowed. Code:
/dev/sda5 /mnt/tempdir ext4 defaults,noexec,uid=1002 0 0 |
I am not sure what you are trying to achieve here but this statement of yours:
Quote:
In other words, my guess is that your problem might already be addressed by a simple Code:
chown -R your_user:your_user /mnt/tempdir I might be missing something here, though. On a separate note, your other issue (running commands at startup with root privileges) can be solved in several ways: - You can put a @reboot entry in to root's crontab - You can add hooks to your init process (the way how to do this depends on your init) - You can put the stuff into a script and make it sudo-executable with NOPASSWD permissions in the sudoers file. Make sure it is writable only by root for security reasons and then run it prefixed with sudo in your autostart config for your x session... There are probably many pther ways. The .bashrc approach you suggested has the downside of being run every time you open a shell - seems like a bit of an overkill. But again, for your specific issue I don't think any of this is needed. Just set the right permissions/ownership once and the result should be persistent across reboots. |
You can add noauto so it doesn't mount automagically and therefor as root at boot. Or uid as suggested above. Also umask if you want everyone to have all permissions. But in general, the user who mounts the drive has the permissions for the drive. Outside of the actual permissions of the contents of the drive. I tend to create a directory under the / of the device with the users permissions. That way it doesn't matter so much that root mounted it. But that's probably not the preferred way with multiple machines, multiple users, enterprise environments and the likes.
|
Quote:
I am experimenting on a CentOS7 virtual machine. |
Quote:
Quote:
Am using CentOS7 virtual machine for learning. Systemd init process is new to me... I suspect there should be a config or script file that is called after all the filesystems from /etc/fstab for the user account has been mounted.... Quote:
even if you can specify NOPASSWD, do you still have to use the sudo prefix in command line? |
Quote:
# mkdir /mnt/partition3/someuser # chown someuser:someuser /mnt/partition3/someuser # umount /dev/sda3 And next time it's mounted, that directory with that users permissions (someuser in this case) has permissions to it's self owned directory. Granted this does add an extra name on the path since that user does not have access to the root directory of the mounted filesystem. Baring filesystems that have no permissions anyway. Also note that the permissions is based on user id (1000+), so if you move between machines and the same user is there but does NOT have the same id, then that's an issue. Which is where it starts to fail in business circles. |
Quote:
Quote:
I'd have to look this up myself for systemd, but it certainly can be done. Quote:
Code:
visudo Then add an entry Code:
ALL ALL = NOPASSWD: /path/to/your/script Code:
sudo /path/to/your/script But as said before, for your specific problem none of this should be needed. |
All times are GMT -5. The time now is 04:47 AM. |