#!/bin/sh
# N password logins of the LDAP user over ssh; counts how many got a shell and what sshd/unix_chkpwd logged.
n=${1:-60}; ok=0; since=$(date '+%F %T'); sudo dmesg -C
i=0; while [ $i -lt $n ]; do
  sshpass -p userpw ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password -o PubkeyAuthentication=no ldapuser@127.0.0.1 true 2>/dev/null && ok=$((ok+1)); i=$((i+1)); done
echo "logins=$n succeeded=$ok denied=$((n-ok))"
sudo journalctl --since "$since" -q --no-pager -o cat -t unix_chkpwd -t sshd-session | grep -E 'could not obtain|Access denied' | sed -E 's/port [0-9]+//' | sort | uniq -c
sudo dmesg | grep -o 'apparmor="[A-Z]*" operation="[a-z_]*".*profile="unix-chkpwd" name="[^"]*"' | sed 's/ error=-13//' | sort | uniq -c
