Shehbaz Jaffer
Shehbaz Jaffer

Reputation: 2014

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.

Upvotes: 2

Views: 22016

Answers (3)

Erik Lievaart
Erik Lievaart

Reputation: 433

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)

Upvotes: 7

peeyush
peeyush

Reputation: 2931

You can allow that user to mount without needing sudo power.

Use NOPASSWD directory

Follow this Link.

Or you may prefer to write expect script which will have password written and password will be entered when it prompts for it.

Upvotes: -2

Igor Chubin
Igor Chubin

Reputation: 64613

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

Upvotes: 1

Related Questions