How to seutp Samba File Server in Rocky Linux 8/9
Introduction
Samba is a software suite that allows Linux servers to share files and printers with Windows clients.
It uses the SMB/CIFS protocol and is widely used in enterprises for file sharing and collaboration.
Why Use Samba?
- Share directories between Linux and Windows systems.
- Create user-specific or common shared directories.
- Implement access control and security on file shares.
- Useful in offices, classrooms, or enterprise environments.
Server Information
Server IP: 192.168.1.100 Package Name: samba, samba-client, samba-common Configuration File: /etc/samba/smb.conf Ports: TCP 139, TCP 445 Service Name: smb, nmb
Install Samba Server
# On Rocky/RedHat/CentOS
dnf install samba samba-client samba-common -y
systemctl enable --now smb nmb
systemctl status smb
Configure Samba Share
Edit the configuration file /etc/samba/smb.conf
to add shares:
[common]
path = /srv/samba/common
browseable = yes
writable = yes
guest ok = no
valid users = @sambashare
[user1]
path = /srv/samba/user1
browseable = no
writable = yes
valid users = user1
Create Shared Directories and Set Permissions
mkdir -p /srv/samba/common
mkdir -p /srv/samba/user1
# Set owner and permissions
chown -R root:sambashare /srv/samba/common
chmod -R 2770 /srv/samba/common
chown -R user1:sambashare /srv/samba/user1
chmod -R 700 /srv/samba/user1
# Create samba group and add users
groupadd sambashare
usermod -aG sambashare user1
# Set Samba password for users
smbpasswd -a user1
Restart Samba Service
systemctl restart smb nmb
systemctl status smb
Access Samba Share from Windows
- Open Run -> \192.168.1.100\common
- Enter the username and password of the Samba user.
- Map network drive for easier access.
Access Samba Share from Linux
mount -t cifs //192.168.1.100/common /mnt -o username=user1,password=YourPassword
Implement ACL Permissions in Samba
Access Control Lists (ACL) provide granular permissions for directories and files:
setfacl -m u:user1:rwx /srv/samba/common
getfacl /srv/samba/common
Samba Security Best Practices
- Use strong passwords for all Samba users.
- Disable guest access if sensitive data is shared.
- Restrict shares to specific users or groups.
- Regularly monitor
/var/log/samba/
logs for unusual access. - Use firewall to allow only trusted networks to access Samba ports 139 and 445.
Conclusion
Samba is a powerful tool to create Linux file servers accessible from Windows and Linux clients.
By organizing shares for users, implementing ACLs, and following security best practices, Linux administrators can provide a safe, efficient, and collaborative file sharing environment for enterprise or classroom use.