Setup Samba (SMB) Share
Install samba using distro’s package manager. Enable in systemctl.
sudo dnf install samba
sudo systemctl enable smb --now
Setup Firewall
- Create a UFW application profile for Samba at
/etc/ufw/applications.d/samba
[Samba]
title=Samba File Server
description=The Samba software suite is a collection of programs that implements the SMB/CIFS protocol for unix systems, allowing you to serve files and printers to Windows, NT, OS/2 and DOS clients. This protocol is sometimes also referred to as the LanManager or NetBIOS protocol.
ports=137,138/udp|139,445/tcp
- Enable Samba traffic from selected subnets.
sudo ufw allow from $SUBNET to any app Samba
Setup Samba User
sudo smbpasswd -a $USER
Create and Designate a Directory to Share
mkdir ~/share
# SELinux rules. Replace "jack" with the name of your user
sudo semanage fcontext --add --type "samba_share_t" "/home/jack/share(/.*)?"
sudo restorecon -R ~/share
Update /etc/samba/smb.conf
Note: update
/home/jack/share
as necessary.
[share]
comment = My Share
path = /home/jack/share
writeable = yes
browseable = yes
public = yes
create mask = 0644
directory mask = 0755
write list = user
Restart Samba Service
sudo systemctl restart smb
Mounting the Share with Permissions
sudo mount -t cifs \
-o username=${USER},password=${PASSWORD},uid=$(id -u),gid=$(id -g) \
//server-address/sharename \
/mount/path/on/machine
Mounting the Share Automatically with /etc/fstab
- Create a credentials file for the Samba share in
~/.smb
user=myuser
password=mypassword
domain=WORKGROUP
- Create a backup of
/etc/fstab
sudo cp /etc/fstab /etc/fstab.bak
- Append the following to
/etc/fstab
//ip/sharename/ /mount/path cifs credentials=/home/myuser/.smb,uid=userid,gid=groupid 0 0
- Apply the changes to
/etc/fstab
sudo systemctl daemon-reload
sudo mount -a