1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 11:42:08 +00:00
iiab/roles/iiab-admin/templates/profile_ssh_warn.sh

29 lines
1.4 KiB
Bash
Raw Normal View History

2017-09-19 18:00:46 +00:00
#!/bin/bash
2017-05-27 18:09:50 +00:00
2018-10-15 06:46:20 +00:00
function check_user_pwd() {
# $meth (hashing method) is typically '6' which implies 5000 rounds
# of SHA-512 per /etc/login.defs -> /etc/pam.d/common-password
meth=$(sudo grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f2)
salt=$(sudo grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f3)
hash=$(sudo grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f4)
[ $(python3 -c "import crypt; print(crypt.crypt('$2', '\$$meth\$$salt'))") == "\$$meth\$$salt\$$hash" ]
}
# credit to the folks at raspberry pi foundatioon
check_hash () {
if ! id -u iiab-admin > /dev/null 2>&1 ; then return 0 ; fi
if grep -q "^PasswordAuthentication\s*no" /etc/ssh/sshd_config ; then return 0 ; fi
#SHADOW="$(sudo -n grep -E '^iiab-admin:' /etc/shadow 2>/dev/null)"
#test -n "${SHADOW}" || return 0
#if echo $SHADOW | grep -q "iiab-admin:!" ; then return 0 ; fi
#SHADOW_PW=$(echo $SHADOW | cut -d: -f2)
2018-10-15 07:25:07 +00:00
#if [ "$SHADOW_PW" != '{{ iiab_admin_pwd_hash }}' ]; then return 0 ; fi
2018-10-15 07:31:13 +00:00
if check_user_pwd "iiab-admin" "{{ iiab_admin_published_pwd }}"; then
2018-10-15 06:46:20 +00:00
echo -e "\nSSH is enabled and the default password for the 'iiab-admin' user is unchanged."
2018-10-15 07:31:13 +00:00
echo -e "This is a security risk - please log in as user 'iiab-admin' and run 'passwd' to change its password.\n"
2018-10-15 06:46:20 +00:00
fi
2017-05-27 18:09:50 +00:00
}
2017-05-29 16:06:09 +00:00
systemctl is-active {{ sshd_service }} > /dev/null && check_hash
2017-05-27 18:09:50 +00:00
unset check_hash