How to Mount SMB Share on Linux

mount smb share on linux

SMB is a protocol used by Windows-based computers for sharing access to resources on a network. To mount SMB share, Linux kernel now supports SMB3 by default (SMB3.1.1/SMB3.02/SMB3/SMB2.1 dialects are requested by default).

CIFS is a particular implementation of the Server Message Block (SMB) protocol. CIFS is a dialect of SMB.

The cifs-utils provide user-space tools to mount SMB/CIFS share on Linux. In this tutorial, I will show you how to mount smb shares on Linux.

Install cifs-utils on Linux

To mount SMB/CIFS share we required cifs utils package installed on the Linux.

Run the following command to install cifs-utils on Ubuntu and Debian:

$ sudo apt update
$ sudo apt install cifs-utils

To install cifs-utils on RHEL, Centos, or Fedora, type following command:

$ sudo yum install cifs-utils

For Fedora28 and above use dnf package to install cifs-utils:

Mounting a SMB Share using CIFS

In this section, the tutorial will show you the way to mount a SMB share using CIFS on Linux systems.

A SMB share can be mounted on your mount point using 'cifs' option of mount command. In the following example, we use the SMB 1 protocol to mount the share by using the '-o vers=1.0' option:

$ sudo mount -t cifs -o vers=1.0,username=user_name //server_name/share_name /mnt/data

By default, the Linux kernel uses the latest SMB protocol version supported by the operating system. In the following command, we will mount a SMB share without passing the 'vers=' option:

$ sudo mount -t cifs -o username=user_name //server_name/share_name /mnt/data

If the user is in a windows domain, specify the domain as the following command:

$ sudo mount -t cifs -o username=DOMAIN\Administrator,seal,vers=3.0 //server_name/share_name /mnt/data

By default, linux mount windows share with the full permission (rwx or 777). If you want to change the permission on your own, please use the dir_mode and file_mode options to set permission for directory and file.

$ sudo mount -t cifs -o credentials=/etc/credentials,dir_mode=0755,file_mode=0755 //server_name/<share_name> /mnt/data

You also can change the default ownership of user and group by specify the uid (user id) and gid (group id) options.

$ sudo mount -t cifs -o credentials=/etc/credentials,uid=500,gid=500,dir_mode=0755,file_mode=0755 //server_name/share_name /mnt/data

Mount SMB share using smbmount

Smbmount command is used to mount a Linux SMB filesystem. Although it was deprecated and no longer maintained, you still can use smbmount to mount a SMB share by running the following command:

smbmount //Hostname/Username /local/mountpoint -o username=username,password=password,lfs

Here NAS samba share is mounted with lfs (large file system) option enabled. This will avoid errors while copying a large file from NAS storage.

# smbmount // /oraclefiles -o username=LOGINNAME,password=LOGINPASSWORD,lfs

Connect SMB Share  using smbclient

This package is not included by default on most Linux distributions, so you will need to install it with your local package manager.

On Debian and Ubuntu servers install smbclient with the following command:

  • sudo apt-get update
  • sudo apt-get install smbclient

The smbclient is a client program that is part of the Samba suite which acts like a FTP program. You can connect to share, use get and put commands to transfer files.

$ sudo smbclient // -U aloft
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
smb: \>

How to list SMB Share

The smbclient command can be also used to list the shared smb resource on remote Samba Server.

Use the following smbclient -L command to displays the shared smb resources on remote server '':

$ sudo smbclient -L
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
Sharename Type Comment
--------- ---- -------
myshare Disk Mary's and Fred's stuff
IPC$ IPC IPC Service (Samba Server)
root Disk Home Directories
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.23c-2]
Server Comment
--------- -------
Workgroup Master
--------- -------

Fstab entry to mount smb

The fstab entries make sure that your mount is persistent over reboot. The following example shows fstab entries for smb share:

$ sudo cat /etc/fstab
LABEL=/1 / ext3 defaults 1 1
LABEL=SWAP-sda2 swap swap defaults 0 0
// /smbdata cifs user,uid=500,rw,suid, username=aloft,password=aloft123 0 0

Here local user (uid=500) will become the owner of the mounted files. In a similar way, you can specify credentials such as uid=uid number or name of the account/user or group.

The /etc/fstab is readable by everyone so it obviously wouldn’t be a good idea to have your Windows password in it. The way to get around this is, by using what is known as a credentials file.

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd 0 0

Below echo command can be used to create the credentials file:

$ sudo echo username=mywindowsusername > .smbpasswd
$ sudo echo password=mywindowspassword >> .smbpasswd

Modify the permissions on the file so only you have permission to read and write to it.

$ sudo chmod 600 .smbpasswd


In this tutorial, we learned how to mount smb share on Linux. Samba supports using SMB1.0, SMB2.0 and SMB3 and defines server min protocol option in smb.conf file.

On Linux clients, you can install cifs-utils that provides means for mounting SMB/CIFS shares.

If you have any questions or feedback, feel free to leave a comment.

5 Comments... add one

  1. Hi there. just wanted to let you know that if i go through the fstab process, on booting the server asks me for a password for connecting before completely booting. After entering password root to my NAS (and i don't have the root password but the admin password) , the boot process continues but the shares have not been mounted. looking at the syslog file, it tells me that it timed out.

    However, i can do it from the command line with no problem. so i set up a script to mount on boot or to mount with a launcher. problem solve but not as slick as i wanted it!

  2. Well done ...
    Android (if not rooted) don't use ports < 1024. To mount using a custom port :
    sudo mount -t cifs -o username=pi,password=raspberry,port=1445 // /home/pi/Android

    See Smb server "LAN drive" application on Android

    • Big thanks for the ports option!
      It (Android device) will mount by command-line
      Auto-mount in fstab (not .fstab) needed "username=guest,password="" " for an anonymous SMB share through LANdrive.

      Files are browsable but not openable. "user, rw, auto" not needed (no difference)
      -does not auto-mount when option "debug" is entered

      Any ideas on why not?


Leave a Comment