66

I mounted a shared server on my local network using the GUI connect to server and the address I entered was smb://myServer/myFolder. Then i tried to add the shared folder to the /mnt directory so I can access to it through my IDE but I failed even though I tried unmount the server and use the CLI with the command

gio mount smb://myServer/myFolder**.

Anyone had this problem before?

1

8 Answers 8

83

I opened the server i shared and typed ifconfig to get the ip adress. Then I typed this command to list of shares

smbclient -L //myServerIpAdress

Then to mount it I typed these 2 commands: first to create a folder under the /mnt and then to do the mount

sudo mkdir /mnt/myFolder

sudo mount -t cifs -o username=serverUserName //myServerIpAdress/sharename /mnt/myFolder/

Then enter the server's password when asked and your mount is done under /mnt/myFolder

7
  • 27
    I kept seeing this error: mount: /mnt/my-mount-name: cannot mount //<server-ip>/path/to/share read-only., and eventually figured out that I had to install cifs-utils first (sudo apt install cifs-utils). After that the mount command worked.
    – maltem-za
    Nov 28, 2018 at 9:13
  • 3
    I had to add few things: sudo mount -t cifs -o uid=<linuxuser>,username=<serveruser>,dom=<serverdomain> //server/folder /local/folder/ uid to be able to write to the folders; dom to provide the correct domain name; May 27, 2020 at 10:07
  • 5
    If you get the cannot mount read-only error, please run sudo apt-get install cifs-utils
    – Wizard79
    Jul 20, 2020 at 9:27
  • sudo apt install smbclient
    – Mehdi
    Aug 20, 2020 at 8:20
  • 3
    thanks @Wizard79 , after install cifs-utils and use @MiroJanosik command, I've successfully mount SMB folder to my ubuntu
    – Luke
    Jul 27, 2021 at 15:09
26

I just followed the Ubuntu wiki smb guide and it worked for me with Ubuntu 18.04.1

Specifically: I first creating the directory for the mount

sudo mkdir /media/NAS

I added the following line to my fstab

//192.168.1.209/public /media/NAS cifs guest,uid=1000,iocharset=utf8 0 0

and then ran

sudo mount -a

From then my NAS drive was mounted. I have rebooted my machine several times and confirmed that it now mounted and start up for me. For what its worth I'm using an Ethernet connection so it could be configured and up and running quicker than a wi-fi connection would be.

4
  • 12
    This worked for me I just needed to make sure that cifs-utils was installed for. sudo apt-get install cifs-utils. Feb 1, 2019 at 18:48
  • mount error(95): Operation not supported
    – crusy
    Jun 21, 2019 at 8:43
  • Same thing for me @crusy Jul 18, 2019 at 22:20
  • 1
    mount error: cifs filesystem not supported by the system on Windows Subsystem for Linux (not strictly speaking Ubuntu)
    – zypA13510
    Sep 22, 2019 at 6:52
8

Note, that you might better add the SMB protocol version (e.g.vers=1.0) to the mount options. The mount.cifs states to use vers=1.0 as default, but it doesn't and you are trapped with a "host down" error when trying to mount to an older NAS. The above solution then reads

sudo mount -t cifs -o username=serverUserName,vers=1.0 //myServerIpAdress/sharename /mnt/myFolder/

See this solution for details.

1
  • i get 'read-only' error
    – chovy
    Jan 24, 2020 at 22:28
5

If you have installed gvfs-bin you can run:

gvfs-mount smb://username@servername/sharename/

More about gvfs-mount on manpages

Also you can read official wiki Samba/SambaClientGuide

2
  • 2
    This tool has been deprecated, use 'gio mount' instead. Jan 13, 2020 at 16:04
  • 1
    it says "volume doesn't implement mount"
    – chovy
    Jan 24, 2020 at 22:30
5

On Ubuntu 18.04, the GNOME Virtual Filesystem mounted from Nautilus can be found in /run/user/1000/gvfs. For example, one can cd into a Samba share with

cd /run/user/1000/gvfs/smb-share:server=media,share=sda1
2

I always wanted to use stored passwords from my keyring for accessing SMB shares in scripts (backups) on my laptop. My aim was not to expose the passwords in files and use anacron to run the backups. After some testing I came up with this:

  1. Mount your share once via Nautilus and store the password in the keyring
  2. try gio mount smb://<server_name>/<share_name>, what should work without password in your GNOME session
  3. Use the following code in backup scripts:

Example tested on Ubuntu 19.04:

# set the dbus address
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
# export dbus address to get access to user space keyring
export DBUS_SESSION_BUS_ADDRESS
# use new gnome user space mount tool (gvfs-mount is deprecated)
gio mount smb://<server_name>/<share_name>
#sync from gvfs created mount point to home dir 
rsync -rav /var/run/user/$(id -u)/gvfs/smb-share\:server\=<server_name>\,share\=<share_name>/<folder>/ ~/<sync_dest>/

When running the script via anacron from /etc/cron.daily you need to use the user that has access to the keyring, e.g.:

su -c /home/user/scripts/rsync_sript.sh user

1

The answer of @Phoenix87 helped me a lot to get access to a samba-drive that is already mounted via Nautilus, but not shown in VSCode. So I put a link under /home/user/.config/gtk-3.0/bookmarks and now can open a workspace via smb in VSCode too.

0

SMBv1 and shares without password protection get the job done quick and easy. But they are definitely a huge security issues (e.g. WannaCry, etc).

Recommend SMBv3 shares with password protection of shares. Using secured credential files in fstab is probably wise too. Linux client side is very similar to above. See procedures at https://acloudguru.com/blog/engineering/ubuntu-samba-client-setup-and-persistent-shares

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .