How To Setup Samba/CIFS Share on Fedora Server

We are going to setup a Samba/CIFS share on Fedora Server that we will then access from Windows 10.

  1. Install Samba/CIFS server packages
  2. Create user to access share
  3. Configure SELinux and firewall
  4. Connect to erver from Windows

1. Install Samba/CIFS Fedora Server Packages

First we need to install the samba package.

sudo dnf install samba
Installing SMB on Fedora
Samba Dependencies

Next, lets enable the Samba service so it automatically starts when the server boots up.

systemctl enable smb nmb
systemctl start smb

nmb is a “NetBIOS name server that provides NetBIOS over IP naming service to clients”
https://www.samba.org/samba/docs/current/man-html/nmbd.8.html

2. Setup Samba/CIFS User

We now need a user to connect to the Samba share with. You can use the commands below to to create a new user.

pdbedit only configures a current Linux system user for Samba. You can skip creating a new Linux user, but only if there is one already created that you can use.

sudo useradd -m sambaUser
sudo passwd sambaUser
sudo pdbedit -a sambaUser

3. Configure Server SELinux and Firewall Permissions

Configure SELinux permissions with the following command.

sudo setsebool -P samba_enable_home_dirs on

You can also just disable SELinux. Although it is not necessarily recommended.
How To Enable/Disable SELinux

sudo setsebool -P samba_enable_home_dirs on
sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload

4. Test Samba/CIFS Share from Windows

You can now test to see if the share works. Open up Windows Explorer. Type in the IP address of the server and connect.

\\ip-address\sambaUser

It should prompt you for a login. Enter the user and password you set up.

Connecting to Fedora Samba/CIFS server

If it loads, then congratulations! You have successfully setup a Samba/CIFS Share on Fedora Server. Create new directories or files or whatever else you need.

Successfully Connected to Fedora Samba/CIFS Server

Check out the following links for more information about setting up Samba.

https://fedoramagazine.org/fedora-32-simple-local-file-sharing-with-samba/
https://jewelhuq.wordpress.com/2017/12/08/how-to-install-samba-server-in-fedora/

https://fedoramagazine.org/fedora-32-simple-local-file-sharing-with-samba/

Setup Windows File Share for Citrix XenServer

Setup Share in windows

You may need to enable the Network Sharing and discovery in the network sharing center before proceeding with the following steps.

Create a new directory, right click and hit properties.

Under Sharing, hit Advanced Sharing…

Enable the Check mark for “Share this folder” and verify the share name is correct. In this example we are sharing a folder called XenServerShare

Setup Share in XenCenter

From XenCenter, hit add new Storage Repository and run through the wizard. When you get to the Share path put in \\share-ip-address\Share\Path

Example: If the IP address of the computer with the Share is 192.168.1.2 and you shared your Downloads folder, the path would be as follows

\\192.168.1.2\Downloads

Use the share computers username and password to log in to it.

Setup Samba share on Ubuntu

In the following commands change <user_name> and <share_name> to the user you want and the name of the share directory.

Install samba and samba client

sudo apt-get install samba smbclient

Setup Samba user

sudo useradd -m  <user_name>  --shell /bin/false &&  
sudo passwd <user_name>
sudo smbpasswd -a <user_name>

Create Share Directory

sudo mkdir "/home/<user_name>/<share_name>
sudo chown <user_name>:<user_name> /home/<user_name>/<share_name

Make share directory

mkdir /home/<user_name>/<share_name>

Configure Samba conf

Add the following to the bottom of the /etc/smb.conf file. Change the <folder_name>, <user_name> etc to the ones created above.

[<folder_name>] 
path = /home/<user_name>/
<folder_name> valid
users = <user_name>
read only = no

Bash script

You can use the following bash script to automatically install and setup a samba share. Create a file called smb.sh and paste the following in

!/bin/bash

# incredigeek.com
# Ubuntu Samba share auto setup
#
sambaUser="smbuser"
smbFolder="smb_share"
sudo apt-get install samba smbclient
sudo useradd -m ${sambaUser} --shell /bin/false
echo "Enter the password you want to use for the smb user. 4 times."
sudo passwd ${sambaUser}
sudo smbpasswd -a ${sambaUser}
sudo mkdir "/home/${sambaUser}/${smbFolder}"
sudo chown ${sambaUser}:${sambaUser} /home/${sambaUser}/${smbFolder}
sudo echo "[${smbFolder}]" >> /etc/samba/smb.conf
sudo echo "path = /home/${sambaUser}/${smbFolder}" >> /etc/samba/smb.conf
sudo echo "valid users = ${sambaUser}" >> /etc/samba/smb.conf
sudo echo "read only = no" >> /etc/samba/smb.conf
sudo systemctl restart smbd
echo "Samba setup script finished"
echo "Access via $(hostname -I)/${smbFolder} ; username = ${sambaUser} ; password = whatever you put in"

Make executable

chmod +x smb.sh

Execute script

sudo ./smb.sh