mount share cifs folder without sudo

17,842

Solution 1

To be able to mount that folder as a normal user, include the mount options for the cifs folder in the configuration file /etc/fstab, and add the options noauto,user, similar to:

//nas-server/cifsShare /media/user/cifsShare cifs -o username=<username>,noauto,user 0 0

The option noauto will make sure the drive is not mounted during startup, but will nevertheless register all parameters necessary to mount the drive. The option user will allow any user to mount the drive.

With this setup, any user is able to mount the share with the mount command, followed by the path that was specified in fstab where the folder is to be mounted, e.g.

mount /media/user/cifsShare

or followed by the share, as in

mount //nas-server/cifsShare

Easier, probably, will be to mount the share using the file manager (Files in standard Ubuntu 18.04). In standard Files, one mounts a drive by providing the URI, in the form of

smb://server/share

A dialog will pop up to ask login, domain and password. Optionally, these settings can be remembered. You can subsequently make a bookmark for easy one-click access in the future.

This works out of the box in several editions of Ubuntu (stock Ubuntu, but also Kubuntu, Xubuntu, ...) and avoids the need to change system configuration files.

Solution 2

Wanted to add a comment, but I do not have enough rep.

On Ubuntu 20 I got syntax errors when trying to add above mentioned entry:

//nas-server/cifsShare /media/user/cifsShare cifs -o username=<username>,noauto,user 0 0

here is what worked for me:

//192.168.1.106/repos /home/ubuntu/shared-repos  cifs username=<user>,noauto,user 0 0

-o was the offending party.

Share:
17,842

Related videos on Youtube

Hait
Author by

Hait

Updated on September 18, 2022

Comments

  • Hait
    Hait over 1 year

    I want to mount share folder. Curren command line:

    sudo mount -t cifs -o username=USERNAME,password=PASSWD
    

    Is it have some safe way (without permanent sudo and other). Any others utils?

    If this is not possible in general, it will be enough for me to be able to mount only a certain shared folder to a certain place.

  • Hait
    Hait over 5 years
    I use ubuntu from ssh. GUI is not available for me.
  • Morbius1
    Morbius1 over 5 years
    @vanadium, You might want to show a generic fstab entry in your answer with the noauto,user combination so that it is more obvious. Then to mount the share all Hait would have to do is issue a "mount /mountpoint" - without sudo just as you described.
  • Hait
    Hait over 5 years
    Is it right? //<ip_addres>/<resource> /media/<mount_point>/ cifs [user=username>@<domain>],[password=<password>],noauto,‌​user 0 0
  • vanadium
    vanadium over 5 years
    As Morbius suggested, I edited the answer to add a generic fstab entry for improving clarity. GUI not available was not clear for the question. It does not harm to leave that part in.
  • Christian Herenz
    Christian Herenz about 3 years
    I edited the original answer as it was indeed wrong in this respect. Thank you for pointing this out - it saved me some time!
  • Admin
    Admin about 2 years
    You can use user= instead of username=. There's also pass= for pw. See man mount.cifs for more details.
  • Admin
    Admin almost 2 years
    The -o won't parse on my Debian buster system