Sub topic 3
UID/GID mapping and root squash
Network file sharing works because the server and client agree on numeric IDs. NFS sends the numeric user ID (UID) and group ID (GID) of each file owner, so a user with UID 1000 on the client is treated as UID 1000 on the server. Samba instead checks a Samba username and password, then maps that user to a local account.
With NFS, a client's root user (UID 0) could otherwise act as root on the server. The root_squash option, which is on by default, maps remote root to the unprivileged nobody account (UID 65534).
Mounting at boot with /etc/fstab
A mount made with mount disappears at reboot. Add an entry to /etc/fstab to mount it automatically. The _netdev option delays the mount until the network is up.
fileserver:/srv/nfs/projects /mnt/nfs-projects nfs4 defaults,_netdev 0 0
//fileserver/projects /mnt/smb-projects cifs credentials=/root/.smbcreds,vers=3.0,uid=1000,gid=1000,_netdev 0 0Store Samba passwords in a root-only credentials file, not in fstab.
Opening the firewall
The server must accept traffic for each service. On firewalld systems, run:
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reloadSELinux and shared directories
SELinux labels control which processes can read a directory. Label a Samba share and allow NFS exports:
sudo semanage fcontext -a -t samba_share_t "/srv/samba(/.*)?"
sudo restorecon -Rv /srv/samba
sudo setsebool -P samba_export_all_rw on
sudo setsebool -P nfs_export_all_rw onHardening both services
Limit access to your trusted subnet. In smb.conf, add:
[global]
server min protocol = SMB2
map to guest = never
hosts allow = 192.168.1.0/24In /etc/exports, keep root_squash and restrict the subnet. Avoid no_root_squash.
Troubleshooting common problems
Check each layer in order:
sudo exportfs -vshows active NFS exports.showmount -e fileservershows exports from the client side.sudo testparm -scheckssmb.confsyntax.sudo smbstatuslists connected Samba clients.sudo ausearch -m avc -ts recentshows SELinux denials.
Choosing between Samba and NFS
Use NFS for Linux and Unix clients. Use Samba when Windows or macOS clients are involved.
Joining Samba to a domain
A Samba server can join an Active Directory domain as a member. It uses security = ADS and winbind to resolve domain users. This setup is more involved, so treat it as a later step after standalone sharing works.
Exercise
A client root user writes to an NFS export that uses the default options. Which account owns the new file on the server?
Show answer
The file is owned by nobody (UID 65534), because root_squash maps remote root to nobody.