Right way to mount Samba on Debian and Ubuntu

I was trying to mount Samba with following commands:

sudo apt-get update
sudo apt-get install cifs-utils

mkdir -p /mnt/smbshare
sudo mount.cifs //192.168.0.200 /mnt/smbshare -o username=admin,password=1234

Then I create a folder myshare under the samba server and run:

sudo mount.cifs //192.168.0.200/myshare /mnt/smbshare -o username=admin,password=1234

The command mount.cifs actually equals mount -t cifs, you can use anyone.

Both were failed.

With error:

[37666.843417] CIFS: VFS: Malformed UNC in devname

and error:

[37645.799522] CIFS: VFS:  BAD_NETWORK_NAME: \\192.168.0.200\myshare
[37645.800872] CIFS: VFS: cifs_mount failed w/return code = -2

Reason

To mount Samba, we have to specify correct server ip and Sharename.

myshare is not the correct Sharename.

Solution

Install smbclient to get the device name.

sudo apt install smbclient

Use it in the server host.

smbclient -L //192.168.0.200
    Sharename       Type      Comment
    ---------       ----      -------
    _Home1          Disk      1a1fd0dcda5bb1ed0dd3f251eb602eb8
    IPC$            IPC       IPC Service (MAGE20 share)

Mount:

sudo mount.cifs //192.168.0.200/_Home1 /mnt/smbshare -o username=admin,password=1234

Here we replaced the folder name myshareto sharename _Home1.

Auto mount at os start

sudo vim /etc/smbcredentials

Add following:

username=admin
password=1234

Edit fstab with command:

sudo chmod 600 /etc/smbcredentials
sudo vim /etc/fstab

Get your uid and gid with id command:

id

add following line:

//192.168.1.200/share /mnt/smbshare cifs credentials=/etc/smbcredentials,uid=1000,gid=1000,file_mode=0770,dir_mode=0770 0 0

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *