Right way to mount Samba on Debian and Ubuntu

122 , , Leave a Comment

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:

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

# Or mount samba with specifying more options
sudo mount.cifs //192.168.0.200/_Home1 /mnt/smbshare -o username=admin,password=1234,uid=1000,gid=1000,file_mode=0770,dir_mode=0770

Here we replaced the folder name myshareto sharename _Home1.

Auto mount at os start

sudo vim /etc/smbcredentials

Add following:

username=admin
password=1234

Change permission:

sudo chmod 600 /etc/smbcredentials

Get your uid and gid with id command:

id

Edit fstab with command:

sudo vim /etc/fstab

add following line:

//192.168.0.200/_Home1 /mnt/smbshare cifs credentials=/etc/smbcredentials,iocharset=utf8,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 *