Linux Administrator

How to mount SAMBA share (SMBFS) in Linux

mount-samba-share
mm
Written by Santosh Prasad

Linux system can also browse and mount SMB shares. In this article I am going to explain how you can mount SAMBA file system (SMBFS) permanently in Linux. Please note that this can be done whether the server is a Windows machine or a Samba server.

Listing SMB Share Folder

# smbclient –L IP_Address –U username

Where:

-L : Listing of SMB share

OR

# smbclient //192.168.0.5/share_file –U username

For Example:

# smbclient –L 192.168.0.5 –U santosh

Mounting SMB Share on Local Directory

# smbmount //IP_Address/sharename /mountpoint –o username=userid,workgroup=workgroupname

For Example:

# smbmount //192.168.0.5/share_file /mnt –o username=santosh,workgroup=web

Mounting SMB Share with Mount Command

# mount –t smbfs IP_Address:/sharename /mountpoint –o username=userid,workgroup=workgroupname

OR

# mount –t smbfs //IP_Address/sharename /mountpoint –o username=userid,workgroup=workgroupname

For Example:

# mount –t smbfs 192.168.0.5:/share_file /mnt –o username=santosh,workgroup=web

Mounting CIFS (Common Internet File System)

Advanced SMB file system implementation which support RAP (Remote Access Protocol).

# mount –t cifs IP_Address:/sharename /mountpoint –o username=userid,workgroup=workgroupname

For Example:

# mount –t cifs 192.168.0.5:/share_file /mountpoint –o username=santosh,workgroup=web

Mount with Password

# mount -t smbfs -o username=userid,workgroup=workgroupname,password=XXXXX //IP_Address/sharepoint /mountpoint/

For Example:

# mount –t smbfs –o username=santosh,workgroup=web,[email protected] //192.168.0.5/share_file /data

Permanent Mount

For permanent mount you will need to edit /etc/fstab file like below.

# vim /etc/fstab

//192.168.0.6/share_file   /data    smbfs  rw,user,username=santosh,[email protected] 0 0

Save and close the file.

Now run the below command to verify.

# mount -a
OR 
# df -H

For Domain User

# vim /etc/fstab

//192.168.0.5/share_file /data smbfs rw,user,username=prasad,[email protected] 0 0

Save and close.

Above prasad is a domain user.

# mount -a
OR
# df -H

Secure Way To Mount Share Permanently

As you know that /etc/fstab file is visible for all logged in user, So mentioning user and password in /etc/fstab is not a good idea. To overcome this issue just create a credential file in user’s home directory and point that file in /etc/fstab like below.

# cd ~ 
# vim .smbfile
username=santosh
[email protected]

Save and close file.

# chmod 600 .smbfile

Now edit the /etc/fstab file like below.

# vim /etc/fstab

//192.168.0.5/share_file /data smbfs credentials=/home/santosh/.smbfile rw,user 0 0

Save and close file.

Now verify by executing below command.

# mount -a
OR
# df -H

I hope this article will help to mount SMB share on Linux system. If you have any queries and problem please comment in comment section.

Thanks:)

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment