For a Windows client to reach a directory on CentOS, the Samba service must run and the client source, Samba account, share permissions, and Linux file permissions must all agree. This example restricts access to members of a Linux group for /srv/samba/team; it does not enable anonymous access or expose SMB to the public internet.
CentOS Linux 7 reached end of maintenance on 2024-06-30, according to the CentOS Project announcement. Use a maintained distribution for new systems and verify package names and SELinux tools for that release. Do not weaken network or host protections to enable sharing on an old CentOS 7 system.
Install Samba and create a dedicated account
CentOS 7 commonly uses yum; newer RHEL-family releases generally use dnf. Package availability depends on the configured repositories. Create a dedicated group and non-interactive system account for the share instead of using root:
sudo yum install -y samba samba-client
sudo groupadd smbteam
sudo useradd -M -s /sbin/nologin -G smbteam shareuser
sudo smbpasswd -a shareuser
On a newer distribution, use its package manager, such as sudo dnf install -y samba samba-client. smbpasswd -a prompts for a Samba password; a successful run confirms that the Samba user was added. Linux accounts and Samba credentials are separate records: add each user to the permitted Linux group and add a Samba password for that account. Do not put passwords in command arguments or scripts.
Create the directory and configure the share
This creates a dedicated directory writable only by members of smbteam. If the directory already exists or contains application data, do not replace ownership or recursively change permissions before checking its current owner, ACLs, and backups.
sudo install -d -o root -g smbteam -m 2770 /srv/samba/team
ls -ld /srv/samba/team
getenforce
ls -Zd /srv/samba/team
The directory should show smbteam as its group with group read, write, and execute access. The setgid bit makes new subdirectories inherit that group. If getenforce returns Enforcing and the path is not labeled samba_share_t, install the distribution's semanage utility and add a persistent label for the custom share path:
sudo semanage fcontext -a -t samba_share_t '/srv/samba/team(/.*)?'
sudo restorecon -Rv /srv/samba/team
ls -Zd /srv/samba/team
If a local fcontext rule already exists for this path, use -m instead of -a. The final command should show the samba_share_t type; package names for the utility vary by distribution. Do not disable SELinux or enable a broad global write boolean. See the Red Hat Samba server documentation.
Add a share section to /etc/samba/smb.conf. valid users limits Samba accounts; Linux directory permissions and SELinux still make their own access decisions:
[team]
path = /srv/samba/team
browseable = yes
read only = no
valid users = @smbteam
create mask = 0660
directory mask = 2770
read only = no permits writes at the share layer but does not bypass Linux permissions. Set it to yes for a download-only share. See the official smb.conf manual for share parameters.
Validate the configuration, start the service, and restrict network access
Validate the file before starting the service. Clients connecting by IP address or DNS name usually do not need the NetBIOS browsing service nmb; enable it only if legacy network-neighborhood discovery is required and supported by the distribution.
sudo testparm -s
sudo systemctl enable --now smb
systemctl is-active smb
The configuration must pass validation and systemctl is-active must return active before the server is ready. If validation reports an error, fix smb.conf instead of restarting with a broken configuration.
Allow SMB only from trusted LAN or VPN clients. Restrict both the host firewall and cloud security group to the actual client subnet; do not expose the share to the public internet. With firewalld, first identify the zone attached to the service interface, then replace the example zone and documentation-only subnet with controlled values:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --permanent --zone=internal --add-rich-rule='rule family="ipv4" source address="192.0.2.0/24" port port="445" protocol="tcp" accept'
sudo firewall-cmd --reload
192.0.2.0/24 is reserved for documentation and must not be used as a production client range. Replace internal with the zone assigned to the trusted client-facing interface. After reloading, inspect the zone rules and make the cloud security group use the same source restriction.
Verify from a client and locate permission failures
First confirm on the server that the share is listed and the designated user can authenticate:
smbclient -L localhost -U shareuser
smbclient //127.0.0.1/team -U shareuser -c 'ls'
The first command should list the team share, and the second should list its directory contents. A client can then connect using \\server-address\team. To verify writes, create a disposable file in a dedicated test directory and confirm the share account can create, read, and delete it; do not use production files as a write test.
If a client cannot connect, check service state, the host firewall, cloud security group, and client source range. If authentication fails, confirm that the Linux user is in the Samba database and is enabled. If the client connects but cannot write, check read only, valid users, directory group permissions, and SELinux denial logs in that order. Do not use chmod -R 777, guest access, or disabling SELinux as generic fixes.
Limitations
- CentOS Linux 7 reached end of maintenance on 2024-06-30. Packages and protocol defaults on legacy hosts may differ from current distributions; use a maintained operating system for new deployments.
- This configuration is for trusted LAN or VPN clients. Do not expose TCP 445 or legacy NetBIOS ports directly to the internet.
- A Samba account must map to a valid Linux user. Samba credentials and Linux file permissions are managed separately; revoke both the Samba account and group access when a user leaves.
- Keep SELinux enforcing. Custom share paths may need a file context configured for the distribution; the package providing
semanagevaries by release. - Domain controllers, Active Directory, guest access, SMB1 compatibility, and high-availability clusters are outside this guide and require separate identity, protocol, and risk reviews.
FAQ
How do I troubleshoot a Windows client that cannot open the share?
Check the server's smb status and source-network rules first. Then verify the cloud security group, host firewall, server address, route, and TCP 445 connectivity. If local smbclient checks pass but Windows still fails, investigate the network path or cached client credentials before changing the share path.
Samba authentication works, but the share is read-only. How can I locate the cause?
Check the share's read only setting first. Authentication does not guarantee filesystem write access; also verify valid users, Linux group membership, directory permissions, and the SELinux context. The 0660 create mask and 2770 directory mask apply to new objects only; inspect existing files separately. Use testparm and audit logs to check loaded settings and SELinux denials.
What account and permission prerequisites does a new share need?
Each share user needs both account types. Create a Linux account, add it to the required group, and set a separate Samba password. The user must also pass valid users, directory permissions, and SELinux checks. Access by IP or DNS normally needs only smb; legacy network-neighborhood discovery may also require nmb.
Is nmb required when clients connect by IP address?
Usually not. Direct SMB access by IP or DNS uses the smb file service, while nmb supports NetBIOS names and legacy browsing. Confirm that TCP 445 and account authorization work before enabling name-discovery services or opening extra ports. This avoids adding services that the clients do not need.
Related reading
- For filesystem mount checks related to a Samba share, see partitioning and mounting a CentOS data disk.
- Before configuring a service, review server operations checks for permissions and services.
Browse the cloud server category for more server configuration topics.
Community & Resources
- Red Hat Enterprise Linux 9: Samba server configuration: share settings, user authorization, and SELinux contexts; verify commands for the target distribution.
- Samba
smb.confmanual: official definitions for global and share-level settings. - Samba
smbpasswdmanual: account and credential management command details.