[SOLVED] Want to run a script that needs root [to mount network drives] privilege as user
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Want to run a script that needs root [to mount network drives] privilege as user
I've dumped my x86 server and have a Raspberry Pi running all the time with my most used files amd mysql server on, and a RAID NAS that holds everything else. The NAS will be asleep for much of the time and wake up at certain times of the day to back-up the Pi and I can wake up on LAN if there's anything archived on it I need to get at. This will save me a stack of money in electricity bills.
I used to mount my network drive in fstab, but now I can't do that (other than the Pi) because most of the time they're not on. I regularly use mount.cifs to mount network drives and it's easy to knock up a script to launch what I want. I really would like to have a desktop icon to click on to run the scripts, so I can mount the drives, but mount.cifs needs root privilege. So, is there a way to give a scripts like this the requisite privilege? I know I could probably use smb4k, but I don't think it works very well in general and why do that when I can run a little script once and forget about it?
You can still use fstab. Just add options "noauto,user", First disable automatic mount on system boot, and second allow unprivileged users to mount it when necessary. Another possibility is using some automount tool (for example I use "autofs"). It will check if someone is trying access the network resource and then do automatic mount. After some time of inactivity it will unmount.
OK, in the end I edited sudoers, added permissions for me to run specific files in /usr/local/sbin/ that runs mount.cifs with all the appropriate parameters and then wrote a script that runs the script in /usr/local/sbin/ by clicking on a shortcut on the desktop and putting sudo at the front. I had to do #/bin/bash on the first line and I had to make sure run in terminal was selected when I made the shortcut. I think that's one time when sudo is acceptable!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.