How to Mount Windows SMB Share on Linux with CIFS / Linux / CentOS / How to Mount Windows SMB Share on Linux with CIFS

In this article, we’ll look at how to mount a shared network folder hosted on a Windows computer in Linux. Windows uses the SMB (Server Message Block) protocol, formerly known as CIFS (Common Internet File System) to share and access shared folders over the network. On Linux, you can use the cifs-utils or Samba client to access Windows network shares via SMB protocol.

Hint. Port TCP/445 is used to access the shared network folder via SMB/CIFS. UDP ports 137, 138, and TCP ports 139 are used for name resolution. If these ports are closed, you will only be able to connect to a shared folder on Windows by using a host IP address.

Mount Windows Share on Linux with Cifs-util

You can mount a shared folder hosted on a Windows computer using the tools in the cifs-util package. Run this command to install the package:

  • Ubuntu/Debian:
    $ sudo apt-get install cifs-utils
  • CentOS/Oracle/RHEL:
    $ sudo dnf install cifs-utils

Create a mount point:

$ sudo mkdir /mnt/share

You can now mount the SMB share from a Windows computer using the User03 account:

$ sudo mount.cifs // /mnt/share -o user=User03

You must have a Windows user password to connect to a shared folder.

mount cifs share from linux cli

You can set additional parameters when mounting a network SMB folder:

$ sudo mount -t cifs -o username=User03,password=PasswOrd1,uid=1000,iocharset=utf8 // /mnt/share
  • // – shared network folder in Windows;
  • /mnt/share – mount point;
  • -t cifs – specify the type of file system to mount;
  • -o mount options (this option can only be used as root, so sudo is used in the command above);
  • username=User03,password=PasswOrd1 – Name and password of the Windows user who has permission to access the share. If anonymous access to the network folder is allowed on Windows, you can specify the guest username here;
  • iocharset=utf8 – enable support for UTF8 encoding to display the name of files on SMB shares;
  • uid=1000 – use this Linux user as the owner of the files in the mounted folder.

mount windows share on linux with user credentials

By default, Windows shares will be mounted on Linux with full permissions (0755). Add the following options to the command if you want to change the default mount permissions:


Add the following line to the /etc/hosts file if you want to use the computer name instead of the IP address when mounting a Windows share:


If you do not want to enter Windows user credentials in the mount command, you can save them to a file.

For example:

$ mcedit ~/.windowscredentials

Insert into the file:


save file with windows credentials to access shared folder

If you need to use a user account from an Active Directory domain, you will need to add a third line to the file:

domain =

To anonymously mount a Windows folder:


Change file permissions:

$ chmod 600 ~/.windowscredentials

When mounting a shared folder, you can now specify the file path instead of the plaintext credentials:

$ sudo mount -t cifs -o credentials=/home/sysops/.windowscredentials,uid=1000,iocharset=utf8 // /mnt/share

Unmount a shared SMB folder:

$ sudo umount /mnt/share

Automatically Mount Network SBM Shares on Linux

The /etc/fstab file can be used to enable the automatic mounting of a Windows-shared folder on Linux.

$ sudo mcedit /etc/fstab

Add the following string to the file to connect the SMB shared folder:
// /mnt/share cifs user,rw,credentials=/home/sysops/.windowscredentials,iocharset=utf8,nofail,_netdev 0 0

  • rw – mount SBM folder in read/write mode
  • nofail – resume Linux boot if file system mount fails
  • _netdev – indicates that the filesystem is network connected. Linux will not mount such filesystems until networking has been successfully initialized on the host.

You can specify the version of the SMB protocol to be used for the connection (SMB version 1.0 is insecure and disabled by default in modern Windows versions). Add the parameter vers=3.0 to the end of the cifs connection string.

// /mnt/share cifs user,rw,credentials=/home/sysops/.windowscredentials,iocharset=utf8,nofail,_netdev,vers=3.0 0 0

If an incompatible (old version) of SMB is used on the remote Windows host, a connection error will occur:
mount error(112): Host is down 
mount error(95): Operation not supported

To immediately mount a shared folder from the fstab configuration file

$ mount -a

How to Access Windows Share on Linux with a Samba Client

Install the samba-client on Linux:

  • Ubuntu/Debian:
    $ sudo apt-get install smbclient
  • CentOS/Oracle/RHEL:
    $ sudo dnf install smbclient

To view the SMB hosts on the local network:

$ smbtree -N

List the SMB folders that are available on a remote Windows host:

$ smbclient -L // -N

If you have disabled anonymous access in Windows, you will get an error:

session setup failed: NT_STATUS_ACCESS_DENIED

In this case, you must specify the Windows user account that you want to use to access the shared folder:

$ smbclient -L // -U User03

Add the -W option if you want to use a domain user account:

$ smbclient -L // -U User03 –W Domain

linux smblient: list shares on windows

To establish an interactive connection to a Windows network share, use the following command

$ smbclient // -U User03 -W Domain


$ smbclient // -U User03

To access the SMB folder anonymously:

$ smbclient // -U Everyone

After logging in, the following prompt will appear:

smb: \>

List the files in a shared SMB folder:


browse windows shared folder with smblient

Download the file from the Windows shared folder:

get remotefile.txt /home/sysops/localfile.txt

Save a local file from Linux to an SMB directory:

put /home/sysops/localfile.txt remotefile.txt

You can run multiple smbclient commands one after the other:

$ smbclient // -U User03 -c "cd MyFolder; get /mnt/backup/"
You can use the help command to display a full list of commands in smbclient. The syntax of the smbclient commands is similar to the ftp client commands.

An error may occur when using the smbclient command:

Unable to initialize messaging context
smbclient: Can't load /etc/samba/smb.conf - run testparm to debug it.

Create the file /etc/samba/smb.conf to fix the error.

If the SMB 1.0 protocol is disabled on the Windows host, the smbclient connection will fail:

Reconnecting with SMB1 for workgroup listing.
protocol negotiation failed: NT_STATUS_CONNECTION_RESET
Unable to connect with SMB1 -- no workgroup available.

Leave a Reply

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