简体   繁体   中英

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.

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

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM