How to mount smb share on ubuntu 18.04

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

If you have installed gvfs-bin you can run:

gvfs-mount smb://[email protected]/sharename/

More about gvfs-mount on manpages

Also you can read official wiki Samba/SambaClientGuide

Solution 5

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

Solution 6

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

Solution 7

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.

Solution 8

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply