e Learning

Learn How to Install Samba Server on CentOS 7

In a Client Server Network, Linux is preferred as the server operating system and Microsoft Windows use in most of the client computers. So you need a way to share files between your Linux server and the Microsoft Windows Operating System. The most common way to share files between Linux and windows is to configure Linux as File server using Samba server.

In this tutorial we are going to learn how to install and configure the samba server on CentOS 7. After completing this tutorial you should be able to configure your CentOS 7 server as a File server using samba and share files on your CentOS Samba Server with Microsoft Windows Operating System.

For the tutorial, we are going to Install samba server on CentOS 7  and Mount the Samba share on Windows 7 Computer. Following are the steps we are going to follow.

  1. Install Samba Server on CentOS 7
  2. Configure CentOS 7 Firewalld
  3. Create Samba user and setup Password
  4. Configure Samba Share
  5. Configure SeLinux for CentOS Samba Server
  6. Mount Samba share on Windows 7
Step One

Install Samba Server on CentOS 7

Samba is not installed by default on CentOS 7, so installed the samba server using yum install command.

yum install samba

Install Samba Server on CentOS 7

After the installation is finished start smb and nmb services. Also enable smb and nmb services to start at system reboot.

systemctl start smb.service

systemctl start nmb.service

systemctl enable smb.service

systemctl enable nmb.service

Step Two

Configure CentOS 7 Firewalld

Configure Firewalld to allow access  to  the SMB service on the CentOS Samba Server.

firewall-cmd –permanent –add-service=samba

firewall-cmd –reload

Step Three

Create Samba user and setup Password

We are going to need a username and password to access our CentOS Samba Share from a remote computer. I am going to create a new user called “sambauser” (You can use any existing Linux user).

useradd sambauser -s /sbin/nologin

Then setup samba password for sambauser using the smbpasswd command (We cannot use the standard Linux password to access samba share from a remote computer).

smbpasswd -a sambauser

Create Samba user and setup Password on CentOS 7
Step Four

Configure the Samba Share

For this tutorial I am going to create a new folder called documents inside the /var directory to share with windows clients. You can use any existing folder on your CentOS 7 server.

First, create the documents folder using the mkdir command.

mkdir -p /var/documents

Then set sambauser as the owner of the /var/documents folder and give read/write access to the folder.

chown sambauser /var/documents/

chmod 755 /var/documents/

Then append following configuration to the /etc/samba/smb.conf file.

[documents]

path=/var/documents

browseable = yes

read only = no

valid users=sambauser

Save the /etc/samba/smb.conf file and restart the CentOS samba server.

systemctl restart smb nmb

Step Five

Configure SeLinux for CentOS Samba Server

You can skip the following step if you have disabled SeLinux on your CentOS 7 Server, otherwise do the following.

Add the /var/documents/ folder to Selinux policy using semanage command. The SeLinux label of the /var/documents/ folder should be samba_share_t.

semanage fcontext -a -t samba_share_t ‘/var/documents(/.*)?’

restorecon -vvFR /var/documents

You should replace the path ‘/var/documents’ with the path of the folder you want to share on your CentOS 7 Samba Server.

Mount Samba share on Windows 7

Now we can mount the samba share on remote computers. For this tutorial I am going to use Windows 7.

\\192.168.1.10\documents

Mount CentOS Samba share on Windows 7

Once you click the finished button, you will prompt to the samba username and password to mount shared folder.

Configure Group Access on CentOS Samba Share

Instead of giving access to the individual users, we can give permission to a Linux group to access the shared folders.

[accounts]

path=/var/accounts

browseable = yes

read only = no

guest ok = no

valid users = @accounts

force group = accounts

As per the above configuration, we have given permission to the accounts group to access share called “accounts” using valid users = @accounts (@ symbol use to specify group). The members of the accounts group can access the /var/accounts folder using their username and password.

That is how we can install and configure very basic Samba File Server on CentOS 7. Once you know the basic setup you can configure smb.conf file for more advanced options.