74

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?

Pablo Bianchi
  • 17,371
toh19
  • 2,617

8 Answers8

99

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

toh19
  • 2,617
27

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.

Zanna
  • 72,312
Spoonless
  • 371
9

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.

mats1995
  • 119
7

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
Phoenix87
  • 606
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

4

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

Christian
  • 320
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://www.pluralsight.com/resources/blog/cloud/ubuntu-samba-client-setup-and-persistent-shares

dex
  • 5
  • 2