Using Samba to Create Cross-Platform Network Shares
In mixed operating system environments, sharing files between Linux and Windows systems is a common requirement. While NFS excels in Unix/Linux environments, Windows machines primarily use the SMB/CIFS protocol. Samba is the open-source implementation that allows CentOS to act as a file server for Windows clients, seamlessly bridging this gap.
This guide is written specifically for CentOS 8.5 — every command and configuration has been tested and verified to work on this version.
Understanding Samba: The Universal Translator
Samba is a software suite that implements the Server Message Block (SMB) protocol, which is the foundation of Windows file and printer sharing. It allows CentOS to participate in Windows networking, either as a client or server.
The Universal Translator Analogy
Imagine Windows and Linux speaking different languages. Windows uses "SMB" while Linux uses "NFS" and POSIX permissions. Samba acts as a universal translator that allows these systems to communicate seamlessly. When a Windows machine asks for a file in "SMB", Samba translates that request into something the Linux filesystem understands, retrieves the file, and then packages the response back in "SMB" for the Windows client.
| Component | Role | Key Function |
|---|---|---|
| Samba Server | The CentOS machine hosting shared directories | Translates Linux file operations into SMB protocol that Windows understands |
| Windows Client | Any Windows machine accessing the shared data | Accesses the share using native Windows networking (Network Neighborhood) |
| smb.conf | Samba's configuration file | Defines shares, permissions, and security settings |
Implementation: Setting Up Samba on CentOS 8.5
We will now configure CentOS 8.5 as a Samba server to share directories with Windows clients on the network.
Phase 1: Installing and Configuring Samba Server
Scenario: Our CentOS server has an IP of 192.168.1.100. We want to share a directory called /srv/samba/shared with Windows clients on our local network 192.168.1.0/24.
- 1 Install Samba Packages
sudo dnf update -ysudo dnf install -y samba samba-common samba-client💡 Verified on CentOS 8.5 — these packages are available in AppStream.
- 2 Create and Prepare the Share Directory
# Create the directory sudo mkdir -p /srv/samba/shared # Create a dedicated system user for Samba (no login, no home) sudo useradd -r -s /sbin/nologin -d /srv/samba/shared sambashare # Set ownership to the new user sudo chown sambashare:sambashare /srv/samba/shared # Set permissions: 2775 = rwxrwsr-x (group sticky + full group access) sudo chmod 2775 /srv/samba/shared # Set SELinux context (critical on CentOS 8.5) sudo chcon -t samba_share_t /srv/samba/shared💡 Why 2775? The "2" at the start is the setgid bit. It ensures that any new files or folders created inside this directory inherit the group ownership (sambashare). This keeps permissions consistent — especially when multiple users (or Windows clients) write to the share.What Does 2775 Mean?
Linux permissions are often shown as 3 or 4 digits.
2775breaks down like this:- 2 = Set Group ID (setgid) — new items inherit the parent’s group
- 7 = Owner: read (4) + write (2) + execute (1) = full access
- 7 = Group: read + write + execute
- 5 = Others: read (4) + execute (1) = no write
So
drwxrwsr-x— notice the s in group? That’s the setgid in action! - 3 Configure Samba (
/etc/samba/smb.conf)Backup the original config first:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bakNow edit the config:
sudo nano /etc/samba/smb.confReplace the ENTIRE file with this minimal, working configuration:
[global] workgroup = WORKGROUP server string = CentOS 8.5 Samba Server netbios name = centos-samba security = user map to guest = Bad User dns proxy = no hosts allow = 192.168.1. 127.0.0.1 hosts deny = 0.0.0.0/0 [SharedFolder] path = /srv/samba/shared browsable = yes writable = yes guest ok = yes read only = no create mask = 0664 directory mask = 2775 force user = sambashare force group = sambashareConfiguration Explained
workgroup = WORKGROUP— Matches default Windows workgroup.map to guest = Bad User— Allows anonymous access for unknown users.hosts allow/deny— Restricts access to your local network only.guest ok = yes— Enables guest (no password) access — great for labs!force user/group = sambashare— All file operations run as this dedicated user.create mask = 0664— New files: owner/group can read+write, others can only read.directory mask = 2775— New folders inherit group and allow group writes.
- 4 Configure Firewall
sudo firewall-cmd --permanent --add-service=samba sudo firewall-cmd --reload💡 This opens ports 139/tcp, 445/tcp, and related UDP ports needed for SMB.
- 5 Start and Enable Samba Services
sudo systemctl start smb nmb sudo systemctl enable smb nmb💡
smb= file sharing,nmb= NetBIOS name service (needed for Windows discovery). - 6 Test Your Configuration
testparm✅ You should see “Loaded services file OK” and your share listed. Press Enter to exit.
💡 Also test locally:
smbclient -L localhost -U%You should see “SharedFolder” in the output.
⚠️ Security Note: Guest Access
This setup uses guest access — anyone on your network can read/write without a password. Perfect for labs or home use. For production, disable guest access and set up Samba users with smbpasswd -a username.
Phase 2: Accessing the Share from Windows
Now that Samba is running on CentOS, Windows clients can access the shared folder.
- 1 Access via File Explorer
- Open File Explorer
- In the address bar, type:
\\192.168.1.100and press Enter - You should see “SharedFolder” — double-click to open it
- Try creating a file — it should appear instantly on the CentOS server!
💡 If you get “Network path not found,” ensure both machines are on the same network and ping192.168.1.100from Windows first. - 2 Map as Network Drive (Optional)
- In File Explorer, click “This PC”
- Click “Map network drive” in the top menu
- Choose a drive letter (e.g., Z:)
- Folder:
\\192.168.1.100\SharedFolder - ✔️ Check “Reconnect at sign-in”
- ✔️ Check “Connect using different credentials” — then click “Finish”
- When prompted for credentials, click “More choices” → “Use a different account” → enter any username (e.g.,
guest) and leave password blank → OK
✅ Success! You’ve Just Created a Cross-Platform File Share!
Files created on Windows appear instantly on CentOS, and vice versa. You can now collaborate across operating systems seamlessly.
Troubleshooting Common Issues on CentOS 8.5
🔧 1. “You do not have permission to access \\192.168.1.100\SharedFolder”
- ✅ Check SELinux:
ls -Z /srv/samba/shared— should showsamba_share_t - ✅ Check ownership:
ls -ld /srv/samba/shared— should be owned bysambashare:sambashare - ✅ Check permissions: should show
drwxrwsr-x(the 's' is critical) - ✅ Temporarily test with SELinux off:
sudo setenforce 0— if it works, re-enable withsudo setenforce 1and fix context
🔧 2. Windows Can’t Find the Server (“Network Path Not Found”)
- ✅ Ping from Windows:
ping 192.168.1.100— if no reply, fix network/IP first - ✅ Ensure
nmbservice is running:sudo systemctl status nmb - ✅ Check firewall:
sudo firewall-cmd --list-services— should include “samba”
🔧 3. Can See Share But Can’t Write Files
- ✅ Ensure
writable = yesandread only = noin smb.conf - ✅ Ensure Linux permissions:
sudo chmod 2775 /srv/samba/shared - ✅ Ensure
force user = sambashareis set so Windows writes are mapped to a valid Linux user
smbclient -L localhost -U% before troubleshooting from Windows.