Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mount unmount without sudo

I am trying to write a script that would ssh into a host, perform mount operation there, run some other commands and exit.

other commands (cd, cp) do not require sudo privelages but mount option requries sudo permission. I want to write a script that would do:

ssh user@server "mount -t nfs xx.xx.xx.xx:/ /nfs -o rsize=4096,wsize=4096 ; cp pqr rst ; umount /nfs ;" 

and some other non-sudo commands. How can I do this without a sudo option and without entering any passwords when the script is running.

like image 713
Shehbaz Jaffer Avatar asked May 11 '26 18:05

Shehbaz Jaffer


2 Answers

Desktop linux distributions use udisks to grant non-root users limited mounting priviliges.

udisks version 2

udisksctl mount -b [device]

udisks version 1

udisks --mount [device]

Of course, if we are talking about a server VM, then these tools might not be installed. Installing them would require root access (once)

like image 115
Erik Lievaart Avatar answered May 13 '26 17:05

Erik Lievaart


You must add /nfs entry to /etc/fstab on the server host.

In the list of options of the entry must be option user or users (depends on that if you want that user could unmount the filesystem or not).

Example:

xx.xx.xx.xx:/ /nfs nfs rsize=4096,wsize=4096,user 0 0
like image 30
Igor Chubin Avatar answered May 13 '26 16:05

Igor Chubin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!