0

OS: Ubuntu MATE 20.04.1 x64_86

I need to create a network drive to a file server (an environment with NFS and Microsoft Active Directory) and be able to read/write into it via a Bash script. After some googling, I found a solution (the following is part of a larger program in my Bash script that mounts the drive):

readonly srv_conn_str="//remote-usrs-srv/Users$"
mount.cifs "${srv_conn_str}" ~/drive_usr -o username="${user}",password="${password}",dom="AD",vers=1.0

The above code does the job but it works if and only if I run mount.cifs with sudo (root privilege). Now the problem is that this Ubuntu system is actually a virtual machine with GUI, to which multiple users connect. Each of these users need to create the mount point in their ~/drive_usr directory (using his/her Windows account ID and password). So unless, everyone has the password of the sudo user, I don't see any other way to run this command and obviously that is not an option. Therefore, I have two questions:

Question 1: Is there any system level configuration possible allowing to run mount.cifs as a normal user and not only by the system administrator?

Question 2: Before each user closes the current session, should ~/drive_usr be unmounted via the umount command? Now the reason that I ask this question is obviously that I'm really a beginner in this field, so I don't know whether closing a session without unmounting the already mounted network drives via mount.cifs could do any harm to the original data on the remote server, as if we removed a USB stick without unmounting it first which is not recommended and could result in loss of data.


Edit n° 1: (Based on the solution vanadium suggested )

I appended the following line to /etc/fstab:

//remote-usrs-srv/Users$   /home/mylinux_username/drive_usr    cifs user,noauto,rw,suid,exec,dev,iocharset=utf8,username=my_windows_username,domain=AD,vers=2.0                            0            0

This almost solved the problem. Now all I need to do without using sudo is to run the following in my Bash script:

readonly srv_conn_str="//remote-usrs-srv/Users$"
mount.cifs "${srv_conn_str}" ~/drive_usr

Which mounts the drive once the user's Windows password has been provided as a command line argument in my script. However, there are still two problems:

  1. I can mount without using sudo, yet apparently the umount command still needs sudo. What I need is to be able to run mount and umount on ~/drive_usr without sudo privilege.

  2. Initially I had added async option among provided options in /etc/fstab. Yet this generated the following error:

    mount error(22): Invalid argument

And when I run dmesg in order to see what was wrong, this is what I found as error message:

CIFS: Unknown mount option "async"

So do I understand correctly? CIFS is not compatible with async? The reason that I wanted to add async option was that while I was googling to learn more about /etc/fstab, I saw that many suggested that adding this option is rather recommended in order to improve the performance, being really a beginner in this field, I don't know whether this is correct. I'd appreciate for some clarification on this.

4
  • Did you try confguring the mount using fstab? With the option noauto, the mount will not be effectuated at startup, and with the option users, users will be allowed to mount and unmount anytime.
    – vanadium
    Sep 27, 2020 at 10:07
  • Thank you very much for your help. I modified my post accordingly based on your suggestion. Please view the Edit part.
    – user17911
    Sep 27, 2020 at 18:27
  • umount should also work. Are you sure you tried unmounting as the same user who mounted? Eventually try the users option: then anyone can mount and anyone (including someone else) can unmount. With respect to async: feel free to ask another question. This site has a format where one asks one question at a time.
    – vanadium
    Sep 28, 2020 at 15:55
  • I confirm that using 'users' instead of 'user' solved that mount/umount issue for normal users. Many thanks for your time and your help. For other issues I'll ask separate questions as you pointed out.
    – user17911
    Oct 2, 2020 at 19:58

1 Answer 1

0

I followed what wanadium suggested in comments (many thanks!) which solved the issue for normal users being unable to mount/unmount. Here is the line that had to be added to /etc/fstab

//remote-usrs-srv/Users$   /home/mylinux_username/drive_usr    cifs    users,noauto,rw,suid,exec,dev,iocharset=utf8,username=my_windows_username,domain=AD,vers=2.0                            0            0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.