如何在重启后无需 root 登录即可将 NAS 永久安装为驱动器?

如何在重启后无需 root 登录即可将 NAS 永久安装为驱动器?

我在笔记本电脑上安装了 Ubuntu 20.04。它用作服务器,我想将 NAS 永久连接到它。这样在自动重启后,NAS 仍会作为驱动器安装。

使用 fstab 我可以成功挂载它,如下所示:

//{NAS_IP}/MyFolder /media/NAS/ cifs 用户名={用户名},密码={密码},rw,uid=1000,gid=500

但是,一旦笔记本电脑重新启动(或关闭并启动)(自动登录),就会出现以下消息:

“仅允许 root 执行挂载操作”

我首先必须在终端中输入 sudo mount -a,然后访问才能再次正常工作。如何才能在每次重启后不输入 root 密码的情况下嵌入它?

谢谢你的回答

答案1

       password=arg|pass=arg
              specifies the CIFS password. If this option  is  not  given  then  the  environment
              variable  PASSWD  is  used. If the password is not specified directly or indirectly
              via an argument to mount, mount.cifs will prompt for a password, unless  the  guest
              option is specified.

              Note that a password which contains the delimiter character (i.e. a comma ',') will
              fail to be parsed correctly on the command line. However, the same password defined
              in the PASSWD environment variable or via a credentials file (see below) or entered
              at the password prompt will be read correctly.

使用 :credentials=/path/to/file代替userrname=...,password=...

       credentials=filename|cred=filename
              specifies a file that contains a username and/or password and optionally  the  name
              of the workgroup. The format of the file is:

                 username=value
                 password=value
                 domain=value

              This  is  preferred  over  having  passwords in plaintext in a shared file, such as
              /etc/fstab . Be sure to protect any credentials file properly.

这应该在启动时起作用。 - 至少对于我在不同位置和设置中的几个服务器来说是这样。

相关内容