Sub topic 16
Troubleshooting common problems
This chapter assumes you have already set up a Samba share and an NFS export as in the earlier chapters. You should be comfortable with systemctl, journalctl, firewall-cmd, and basic SELinux commands. The aim is a repeatable method for finding which layer is broken, plus the errors you will see most often.
Work from the bottom up
File sharing fails in layers. A permission problem on the server looks the same to the user as a blocked port ("it doesn't work"), but the fixes are unrelated. Test each layer in order and stop at the first one that fails.
Reachability and ports
Run these from the client first. nc is the netcat tool. Port 445 is SMB and port 2049 is NFS.
getent hosts fileserver
ping -c 2 fileserver
nc -zv fileserver 445
nc -zv fileserver 2049If the port test fails, move to the server and check that the daemon is listening and that the firewall allows it:
sudo ss -tlnp | grep -E ':445|:2049'
sudo firewall-cmd --list-services
sudo systemctl status smbd nfs-serverOn Red Hat-family systems the Samba unit is smb, not smbd. A refused connection usually means the daemon is not running. A timeout usually means a firewall is silently dropping packets.
Samba problems
Start on the server. testparm -s catches syntax errors and unknown parameters. smbclient -L tests the full path from the client, including authentication. The log at /var/log/samba/log.smbd and journalctl -u smbd show why a request was refused.
sudo testparm -s
smbclient -L //fileserver -U alice
sudo smbstatus
sudo tail -n 50 /var/log/samba/log.smbdsmbstatus lists the current connections, the open files, and any locks. Use it to confirm that the user really connected, and as which user.
| Symptom | Likely cause | Fix |
|---|---|---|
| `NT_STATUS_LOGON_FAILURE` | Wrong password, or the user has no Samba account. The Samba password is separate from the login password. | `sudo smbpasswd -a alice`, then retry. |
| `NT_STATUS_BAD_NETWORK_NAME` | The share name does not exist in `smb.conf`. | Check the `[section]` name and rerun `testparm`. |
| `NT_STATUS_ACCESS_DENIED` after login | `valid users` excludes the user, or Unix permissions deny access. | Check `id alice` and the directory mode. |
| `NT_STATUS_CONNECTION_REFUSED` | `smbd` is not running or not listening. | Start the service and check `ss`. |
| `mount error(13): Permission denied` | Bad credentials, or a protocol mismatch. | Retry with `smbclient`, then set `vers=` explicitly. |
| `mount error(112)` or `(115)` | Host unreachable or timed out. | Check the network and firewall. |
Two Samba mistakes are common. First, smbpasswd -a only works for a user who already exists in /etc/passwd. Second, group membership is read when the client connects. If you add alice to staff while she has a mount open, she must disconnect and reconnect before valid users = @staff sees the change.
Files created through the share should be group-writable. If other members of the group cannot edit them, check create mask, directory mask, force group, and the setgid bit on the directory (chmod 2775).
NFS problems
On the server, confirm what is actually exported. Don't rely on what you think is in /etc/exports.
sudo exportfs -v
sudo exportfs -ra
sudo journalctl -u nfs-server --since "10 minutes ago"On the client, nfsstat -m shows the options in effect for each NFS mount, including the protocol version.
nfsstat -m
showmount -e fileserverA single space in /etc/exports changes the meaning of a line. Compare these two:
/srv/nfs/projects 192.168.1.0/24(rw,sync,no_subtree_check)
/srv/nfs/projects 192.168.1.0/24 (rw,sync,no_subtree_check)The first exports read-write to the subnet only. In the second, the subnet gets default options (read-only), and every other host gets read-write access. exportfs -v shows the result, so check it after every edit.
| Message | Likely cause | Fix |
|---|---|---|
| `access denied by server while mounting` | The client's address is not in the export's client list. | Fix the subnet in `/etc/exports`, then run `exportfs -ra`. |
| `No route to host` | A firewall rejected the connection. | Open the `nfs` service in firewalld. |
| `Connection timed out` | Packets are dropped, or the server is down. | Test with `nc -zv fileserver 2049`. |
| `No such file or directory` | The path is not exported, or it is mistyped. | Compare with `exportfs -v`. |
| `Stale file handle` | The export or its underlying filesystem changed while the client had it mounted. | `sudo umount -l /mnt/projects`, then mount again. |
| Files owned by `nobody` or writes denied for root | `root_squash` maps client root to an unprivileged user. | Use a normal user, or fix the UID/GID mapping. Avoid `no_root_squash`. |
Permission errors on files that mount fine are almost always a UID/GID mismatch. NFS compares numeric IDs, not names. Run id alice on both machines. If the numbers differ, the server treats the client user as someone else.
A client with a default hard mount waits forever when the server disappears, so commands such as ls and df hang. Use umount -f or umount -l to clear it. Don't switch to soft mounts just to avoid hangs, because a timed-out write can silently lose data.
Mounts that fail at boot
A bad /etc/fstab line can stall boot while systemd waits for the network. Always test the file before rebooting.
sudo mount -a
findmnt --verify
ls -l /root/.smbcredsThe credentials file for CIFS should be mode 600 and owned by root. Keep _netdev on network mounts. For non-essential shares, add nofail so a missing server does not drop the machine into emergency mode. You can also add x-systemd.automount to mount the share on first access.
SELinux denials
If the Unix permissions are correct and the firewall is open but access is still denied, check SELinux. Look for recent denials and the label on the directory:
sudo ausearch -m avc -ts recent
ls -Zd /srv/samba/projects
getsebool -a | grep -E 'samba_export|nfs_export'A directory shared by Samba needs the samba_share_t label. Set it persistently with semanage fcontext, then apply it with restorecon. A plain chcon change is lost on a filesystem relabel.
sudo semanage fcontext -a -t samba_share_t "/srv/samba/projects(/.*)?"
sudo restorecon -Rv /srv/samba/projects
sudo setsebool -P samba_export_all_rw onUse the broad boolean only if the label approach does not fit. For NFS exports, the equivalent boolean is nfs_export_all_rw.
Exercise
A client runs sudo mount -t nfs4 fileserver:/srv/nfs/projects /mnt/projects and gets "access denied by server while mounting". nc -zv fileserver 2049 succeeds. Which command do you run on the server to find the cause, and what do you look for?
Show answer
Run sudo exportfs -v. Port 2049 is reachable, so the firewall is not the problem. Check that /srv/nfs/projects is listed and that the client list covers the client's IP address. A wrong subnet is the usual cause. Also look for a stray space between the host and the options. After correcting /etc/exports, run sudo exportfs -ra and retry the mount.
Exercise
A Samba user can mount the share, but creating a file fails with "Permission denied". testparm reports no errors and smbstatus shows the connection. List the next three things to check.
Show answer
First, run id alice to confirm she is in staff, and reconnect if she was added recently. Second, run ls -ld /srv/samba/projects to check that the group has write permission and the setgid bit is set (mode 2775). Third, run ls -Zd on the directory and sudo ausearch -m avc -ts recent to look for an SELinux denial, then fix the label with semanage fcontext and restorecon.