Set up Samba client on CentOS/RHEL 7 for file sharing on Windows.
Tags: samba, centos, windows, linux
Published: 2022-01-23 01:37:28

This article is intended as a general guide. Installing and configuring a SAMBA client on CENTOS 7 for file sharing on Windows.

![Banner](https://miro.medium.com/max/2258/1*5YanQ1DHD6UCpvVavS-MyA.png)

## Step 1 — Check windows machine Workgroups
Before you proceed to configure samba, make sure the Windows machine is in the same workgroup to be configured on the CentOS server. To check the value in windows machine run the command at cmd prompt:
```bash
net config workstation
```
![Workspace visualization](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d47yqsc6fnyayvnk1kpb.png)
## Step 2 — Install SAMBA
First install Samba4 and required packages from the default CentOS repositories using the:
```bash
dnf install samba* -y
```
## Step 3 — Configure
The main samba configuration file is:
```bash
nano /etc/samba/smb.conf
```
But, before configuring samba, I suggest you to take a backup of the default file like this.
```bash
cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
```
Edit the file according to your needs. In my case I will share the /var/www/html folder and allow the smbgrp group to access it.
![Config file 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqksjqg6oiecpp7r8xul.png)
![Config file 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39gup0f26ryl4pq7hiy3.png)
### Secure Samba file sharing
As root, create the user you want to access the shared folder. In my case I will be creating a group “smbgrp” allowed to access the shared folder. This allows you to add more users in the future.
```bash
groupadd smbgrp
# Assign your user to this group.
usermod user -aG smbgrp
# Set a password for this user.
sudo smbpasswd -a user
# Also set the appropriate permissions on the directory.
chmod -R 0775 /var/www/html
# Assign the full control of the shared folder to the user.
chown -R user:smbgrp /var/www/html
```
In my case, I will be sharing the html folder in /var/www/html. This is useful for web developers, because lets you edit in realtime a file in the centos server from windows. In a classic Apache HTTP server.
## Allow Samba server default ports through firewall
```
firewall-cmd --permanent --add-port=137/tcp
firewall-cmd --permanent --add-port=138/tcp
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp
firewall-cmd --permanent --add-port=901/tcp
firewall-cmd --reload
```
### Restart SAMBA services:
```
systemctl start smb
systemctl start nmb
systemctl status smb
systemctl status nmb
```
## Step 4 — Verify the shared folder
In order to verify the correct installation, create an example file in the shared folder with touch:
```
touch /var/www/html/hola.txt
```
In windows, press “Windows Key+R” and submit your ip address, preceded by two inverted slashes: \\
![Enter to host](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4q36wi7i1bjagtyr88i5.png)
You will see your shared folder like this:
![Shared folder visualization](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v7i76pbbvm2q9qt3tey.png)
If you set the user and folder permissions as described before, you should see a login window. In which you must enter your centOS user and the password selected.
![Login Step](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifrql343s3oeg26r2fi8.png)
There is the hola.txt file created from centOS 7.
![File created from linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b8dnnolf8zurtvutqznq.png)
Finally, start and enable samba services to start automatically at next boot:
```
systemctl enable smb.service
systemctl enable nmb.service
systemctl start smb.service
systemctl start nmb.service
```
## # Conclusion
Setting up Samba is easy, and something to consider if you want easy file sharing between Linux and Windows machines, or even Linux and Linux machines. I gave some context of how to set it up, but there are tons of use cases for Samba. You can also tie it in to different authentication/authorization schemes if you’d like an use it with Active Directory as well. Check out Samba.org for more information.