How to mount Windows shares or Samba on Linux Centos and Ubuntu

Mount Windows shares or Samba on Linux Centos and Ubuntu

If we need to work together with team or access windows storage, we need to mount remote windows share or Samba on CentOS 7.

Mounting Windows or other samba) shares is done through the cifs virtual file system client (cifs vfs) implemented in kernel and a mount helper mount.cifs.

If we are managing a multi user system, consider setting the dir_mode and file_mode options to your mount point.

The default behaviour for mount.cifs is leaving the mounted share unsecured (

For Centos:

# yum install samba-client samba-common cifs-utils

For Ubuntu:

# sudo apt-get install cifs-utils samba-common system-config-samba samba winbind

Example output:

[root@pion ~]# yum install samba-client samba-common cifs-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * remi-safe:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0:6.2-10.el7 will be installed
--> Processing Dependency: for package: cifs-utils-6.2-10.el7.x86_64
--> Running transaction check
---> Package libtdb.x86_64 0:1.3.16-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved


  cifs-utils.x86_64 0:6.2-10.el7                       samba-client.x86_64 0:4.9.1-6.el7                       samba-common.noarch 0:4.9.1-6.el7

Dependency Installed:
  libldb.x86_64 0:1.4.2-1.el7          libsmbclient.x86_64 0:4.9.1-6.el7      libtalloc.x86_64 0:2.1.14-1.el7             libtdb.x86_64 0:1.3.16-1.el7
  libtevent.x86_64 0:0.9.37-1.el7      libwbclient.x86_64 0:4.9.1-6.el7       samba-client-libs.x86_64 0:4.9.1-6.el7      samba-common-libs.x86_64 0:4.9.1-6.el7


Create a local mount point directory, for example:

# mkdir /mnt/windows

Example Windows share detail is:

Remote Windows machine ip address is
share name : storage-photo
username: pion
password: my_password

# mount.cifs // /mnt/windows-storage -o rw,username=pion,password=my_password

If you want to auto mount on boot, edit /etc/fstab and add the following mount command:

\\\storage-photo /mnt/windows cifs user,uid=1001,rw,suid,username=pion,password=my_password 0 0

The problem from above samba mount configuration is username and password visible to all user.

So we need make it more secure. Put username and password on /root/secret.txt and put your username and password with format:

\\\storage-photo /mnt/windows cifs credentials=/root/secret.txt,rw,_netdev,uid=1001,gid=1001 0 0

We have free backup storage box backup on Hetzner.

This is great feature from Hetzner if you rent Dedicated server with middle or high specs.

This is how we mount storage box using cifs and keep the cradentials on /root directory.

Mount Hetzner backup storage box using cifs



Leave a Reply

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