简体   繁体   English

不使用sudo挂载

[英]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. 我正在尝试编写一个脚本,该脚本将ssh到主机中,在该主机中执行挂载操作,运行其他命令并退出。

other commands (cd, cp) do not require sudo privelages but mount option requries sudo permission. 其他命令(cd,cp)不需要sudo权限,但安装选项需要sudo权限。 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. 和其他一些非sudo命令。 How can I do this without a sudo option and without entering any passwords when the script is running. 在脚本运行时,如何在没有sudo选项且没有输入任何密码的情况下执行此操作。

You must add /nfs entry to /etc/fstab on the server host. 您必须将/nfs条目添加到server主机上的/etc/fstab

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). 在入境的选项列表必须选择userusers (取决于如果你希望用户可以卸载文件系统或没有)。

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. 桌面linux发行版使用udisk授予非root用户有限的安装特权。

udisks version 2 udisks版本2

udisksctl mount -b [device]

udisks version 1 udisks版本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) 安装它们将需要root访问权限(一次)

You can allow that user to mount without needing sudo power. 您可以允许该用户挂载而无需sudo权限。

Use NOPASSWD directory 使用NOPASSWD目录

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. 或者,您可能更喜欢编写Expect脚本,该脚本将写入密码,并在提示输入密码时输入密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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