Information
While the system administrator can establish secure permissions for users' home directories, the users can easily override these.
Group or world-writable user home directories may enable malicious users to steal or modify other users' data or to gain another user's system privileges.
Solution
Making global modifications to user home directories without alerting the user community can result in unexpected outages and unhappy users. Therefore, it is recommended that a monitoring policy be established to report user file permissions and determine the action to be taken in accordance with site policy.
The following script can be used to remove permissions is excess of 750 from users' home directories:
#!/bin/bash
awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(/usr)?/sbin/nologin(/)?$/ && $7!~/(/usr)?/bin/false(/)?$/) {print $6}' /etc/passwd | while read -r dir; do
if [ -d "$dir" ]; then
dirperm=$(stat -L -c "%A" "$dir")
if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then
chmod g-w,o-rwx "$dir"
fi
fi
done