RHEL NFS and Samba File Services
A network share combines storage, protocol, identity mapping, access policy, firewall, SELinux, name service, locking and client caching. A successful mount does not prove correct authorization, and root on a client does not automatically equal root on the server. Select NFS for Unix-oriented shared files and Samba when SMB interoperability and Windows identity behavior are required; do not run both over one tree without a deliberate locking and permission design.
Choose protocol and identity before configuration
NFSv4 uses a pseudo-filesystem and stateful protocol behavior; export options and identity mapping must match the trust model. Samba maps SMB identities and permissions through its security mode, passdb or directory integration and filesystem ACLs. Manage Samba through supported configuration files, validation commands and approved automation.
IP-based export restrictions do not authenticate a person. Kerberos-backed NFS or directory-integrated SMB may be required for stronger identity. Protect data in transit and at rest according to classification.
Build an evidence map
| Layer | Question to answer | Evidence |
|---|---|---|
| Client identity | Which user principal and numeric/directory mapping apply? | id/getent, Kerberos or SMB session |
| Network | Can required protocol reach the server? | DNS, route, firewalld service and socket |
| Service policy | Which export/share and options match? | exportfs or testparm |
| Host access | Do DAC, ACL and SELinux permit the service? | namei/getfacl/labels/AVC |
| Data behavior | Are locking, caching and recovery acceptable? | application test, locks and failure/reconnect |
Operating sequence
- Define clients, identities, data ownership, protocol and recovery expectations.
- Prepare a dedicated filesystem path with least-privilege owner, group and ACL.
- Assign the documented SELinux context/boolean for the intended service.
- Create one source-scoped export or share and validate configuration.
- Open only the named firewalld service for the approved zone/source.
- Mount/connect from an intended client and test create/read/update/rename/lock.
- Test an unapproved identity/source and a server restart or network interruption.
Commands and expected evidence
exportfs -v
exportfs -rav
showmount -e server.example 2>/dev/null
findmnt -t nfs,nfs4
nfsstat -m
smbd -b 2>/dev/null | head
testparm -s
smbclient -L //server.example -U labuser
smbstatus
getfacl -p /srv/share
ls -ldZ /srv/share
firewall-cmd --list-servicesshowmounthas protocol/version limits and is not a complete NFSv4 authorization test.- Validate Samba configuration with
testparm, then test the actual identity and share operation. - Avoid empty Samba passwords and guest write access for business data.
- Use stable mount dependencies and automount where appropriate instead of hiding required-share failures.
Evidence and acceptance criteria
| Evidence | Healthy result | Failure meaning |
|---|---|---|
| Identity | Client principal maps to expected server account/group | UID collision or directory/credential issue |
| Service config | Export/share validator shows exact path and scope | Syntax, include or option mismatch |
| Policy | Firewall and SELinux permit only intended service/path | Network open but host policy denial |
| Operation | Create/read/rename/lock semantics match workload | Mount alone hides permission or locking failure |
| Recovery | Reconnect and data integrity pass interruption test | Stale handles, lock or application corruption risk |
Worked operating scenario
An NFS client can mount a share but an application cannot write. The directory is group-writable, yet the client UID maps to another server identity and SELinux labels the custom path for unrelated content. Widening the mode would not correct either issue.
The team reconciles authoritative UID/GID mapping, assigns the service-specific persistent file context, restores labels and tests as the actual application account. An unapproved account remains denied.
Practical how-to cases
Case 1: Export an NFS directory
Create a bounded export, validate it and open only the NFS service. Choose NFS for Unix-style sharing and SMB for Windows interoperability, then align identity, firewall and SELinux.
sudo dnf install -y nfs-utils
sudo install -d -m 2770 -o root -g shared /srv/nfs/project
printf '/srv/nfs/project 192.0.2.0/24(rw,sync,root_squash)\n' | sudo tee /etc/exports.d/project.exports
sudo exportfs -rav
sudo exportfs -v
sudo firewall-cmd --permanent --add-service=nfs| Checkpoint | What to establish |
|---|---|
| Expected result | Only the intended network receives the export and root_squash remains effective. |
| If it fails | Client UID/GID mismatch or SELinux labeling can deny access even when the mount succeeds. |
| Safe recovery | Remove the exact export/share, unmount clients, restore saved configuration and prove no stale mount or unauthorized access remains. |
Case 2: Mount NFS persistently
Test interactively, then add an automount entry that does not block boot. Choose NFS for Unix-style sharing and SMB for Windows interoperability, then align identity, firewall and SELinux.
sudo mount -t nfs4 servera:/srv/nfs/project /mnt/project
findmnt /mnt/project
touch /mnt/project/client-test
printf 'servera:/srv/nfs/project /mnt/project nfs4 rw,_netdev,x-systemd.automount 0 0\n' | sudo tee -a /etc/fstab
sudo findmnt --verify| Checkpoint | What to establish |
|---|---|
| Expected result | The client can perform intended operations and the network mount activates on demand. |
| If it fails | Server reachability, export policy, name mapping and local mount options must be tested separately. |
| Safe recovery | Remove the exact export/share, unmount clients, restore saved configuration and prove no stale mount or unauthorized access remains. |
Case 3: Create a Samba share
Validate smb.conf, provision a Samba password and align SELinux and firewall. Choose NFS for Unix-style sharing and SMB for Windows interoperability, then align identity, firewall and SELinux.
sudo dnf install -y samba samba-client
sudo testparm -s
sudo smbpasswd -a student
sudo semanage fcontext -a -t samba_share_t '/srv/samba/project(/.*)?'
sudo restorecon -RFv /srv/samba/project
sudo firewall-cmd --permanent --add-service=samba
sudo systemctl enable --now smb| Checkpoint | What to establish |
|---|---|
| Expected result | testparm succeeds, the share is listed and the intended user can connect. |
| If it fails | A Linux account and Samba credential are related but separate identities. |
| Safe recovery | Remove the exact export/share, unmount clients, restore saved configuration and prove no stale mount or unauthorized access remains. |
Case 4: Test SMB permissions end to end
Compare share definition, Unix access, SELinux and client operations. Choose NFS for Unix-style sharing and SMB for Windows interoperability, then align identity, firewall and SELinux.
testparm -s
smbclient -L //servera -U student
smbclient //servera/project -U student -c 'ls; put test.txt; ls'
namei -om /srv/samba/project
ls -ldZ /srv/samba/project| Checkpoint | What to establish |
|---|---|
| Expected result | The intended operations work and an unauthorized user is denied. |
| If it fails | Making the directory world-writable masks identity and policy errors rather than solving them. |
| Safe recovery | Remove the exact export/share, unmount clients, restore saved configuration and prove no stale mount or unauthorized access remains. |
Independent practice tasks
- Build an NFS read-only export and verify root squashing.
- Configure autofs for an indirect NFS map.
- Create a group-writable Samba share and test two users.
- Diagnose a share that lists successfully but denies file creation.
For this lesson on RHEL NFS and Samba Services, complete each task without copying the worked command sequence. Record the initial state, exact change, verification, negative test and recovery command. A task is unfinished if it works now but does not survive a reboot where persistence is required.
Troubleshooting by symptom
| Symptom | Inspect first | Defensible next action |
|---|---|---|
| Mount timeout | DNS/route, service sockets, firewall and NFS version | Repair first unreachable layer |
| Mount works, write denied | Mapped identity, ACL/DAC, export/share options and SELinux | Correct exact identity/policy |
| Stale file handle | Server filesystem/export history and client state | Protect application, restore stable export identity/reconnect |
| Samba login loops | Security mode, directory/clock, account mapping and logs | Correct authentication source, not guest fallback |
| Data corruption/locks | Protocol locking, dual access paths and application support | Stop unsafe concurrent access and recover data |
Unsafe operations and recovery boundaries
- Unsafe: exporting
/or broad writable trees expands compromise and deletion scope. - Unsafe:
no_root_squashlets client root act as server root on exported data and requires an exceptional trust design. - Unsafe: combining NFS and SMB access to the same application data without tested locking/identity semantics risks corruption.
Rewritten knowledge checks
testparm, followed by real client identity and operation tests.testparm, then run identity and operation tests.Guided lab and acceptance test
- Create a dedicated lab data path and group.
- Configure either one source-scoped NFS export or authenticated Samba share.
- Apply correct SELinux and firewalld controls.
- Connect from an approved client and test file lifecycle and locking.
- Test denied identity/source and capture server logs.
- Remove client mount, service configuration and lab data in dependency order.