Sub topic 15
Hardening Both Services
Assume you already understand Linux users, groups, file permissions, subnets, systemctl, and basic Samba and NFS configuration. Hardening means reducing who can connect, what they can do, and which protocol features they may use.
Restrict access at several layers
Use the narrowest client network that meets the requirement. A firewall should block unwanted traffic before a service receives it. The service configuration should also restrict clients and users. Finally, normal Unix ownership and mode bits should protect the files.
Do not expose file-sharing services directly to the internet. Allow only trusted networks or specific hosts. Avoid guest access unless you have a deliberate, low-risk use case.
Harden Samba
Disable obsolete SMB1 and require modern protocol features. Requiring SMB3 can prevent older clients from connecting, so test compatibility before enforcing it across a mixed environment. Signing helps detect tampering. Encryption protects file traffic from being read in transit, but it uses additional CPU and may prevent old clients from connecting.
Use authenticated users and groups rather than guest access. Restrict each share with valid users, and use a firewall or hosts allow for network restrictions.
[global]
server role = standalone server
map to guest = never
server min protocol = SMB3_00
server signing = mandatory
smb encrypt = required
hosts allow = 192.168.1.0/24 127.0.0.1
[projects]
path = /srv/samba/projects
read only = no
valid users = @staff
force group = staff
create mask = 0660
directory mask = 0770The directory permissions must agree with the share settings. A writable Samba share cannot grant more access than the underlying Unix permissions allow.
Harden NFS
Export only the required directory to a specific subnet or host. Keep root_squash enabled. It maps requests from client root to an unprivileged identity on the server, reducing the damage caused by a compromised client. Use sync when data safety is more important than maximum write performance.
/srv/nfs/projects 192.168.1.0/24(rw,sync,root_squash,no_subtree_check)NFS normally relies on matching numeric user and group IDs. Keep identity databases synchronized, or use a central identity system. For stronger authentication, consider Kerberos security flavors such as sec=krb5i for integrity or sec=krb5p for privacy. Kerberos requires additional server, client, and identity configuration.
Check the result
After changing Samba, run testparm -s and inspect smbstatus. For NFS, run exportfs -ra followed by exportfs -v. Test from an authorized client and confirm that an unauthorized host, guest user, and obsolete SMB client are rejected. Review service logs when a test fails.
Exercise
Why should both Samba's share rules and the directory's Unix permissions be restricted?
Show answer
Samba rules control network access, while Unix permissions protect the files underneath. Either layer can limit access, but neither should be treated as the only security boundary.