-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode_owner_fix.sh
50 lines (43 loc) · 1.39 KB
/
mode_owner_fix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
version='1.8'
logfile=/var/log/schaubroeck/chmod_fixer.log
debug=true
workingdir=/home/schsup/chmodfix
function log() {
msg=${@}
timestamp=$(date '+%F %T')
if [[ -n ${debug} ]]
then
printf "%18s |%s| %s\n" "${timestamp}" "${version}" "${msg}" | tee -a ${logfile}
else
printf "%18s |%s| %s\n" "${timestamp}" "${version}" "${msg}" >> ${logfile}
fi
}
function list_home_users(){
ls -1 /home > /tmp/home_users
while read usr
do
if [[ $(id $usr > /dev/null; echo $?) -eq 0 ]]
then
# is valid user
if [[ $usr != 'schsup' ]]
then
fix_perms $usr
else
log skipping $usr
fi
usrlog=${workingdir}/$usr
fi
done < /tmp/home_users
}
function fix_perms() {
target=${@}
log Fixing permissions for $target
chown -Rv ${target} /home/${target} > ${usrlog}_chown.log
chmod -Rv 755 /home/${target} > ${usrlog}_chmod.log
[[ -e /home/${target}/.ssh ]] && chmod -Rv 700 /home/${target}/.ssh >> ${usrlog}_chmod.log
[[ -e /home/${target}/.ssh/id_rsa ]] && chmod 600 /home/${target}/.ssh/id_rsa >> ${usrlog}_chmod.log
[[ -e /home/${target}/.ssh/authorized_keys ]] && chmod 644 /home/${target}/.ssh/authorized_keys >> ${usrlog}_chmod.log
}
[[ ! -d ${workingdir} ]] && mkdir ${workingdir}
list_home_users