Untitled

 avatar
unknown
plain_text
22 days ago
756 B
4
Indexable
# Utilisateur a SURVEILLER
USER="root"

# RECUPERER le PID du processus actuel
CURRENT_PID=$$

# Compter le nombre de connexions SSH actives pour l'utilisateur root
# Sur FreeBSD, on utilise `ps -aux` pour recuperer les informations de processus
CONN_COUNT=$(ps -ef | grep 'USER=root' | grep -v grep | wc -l)

# Exclure la connexion SSH actuelle si l'utilisateur executant le script est root
if [[ "$USER" == "$(whoami)" && $(ps -p $CURRENT_PID -o comm=) == "sshd" ]]; then
    CONN_COUNT=$((CONN_COUNT - 1))
fi

# VERIFIER le nombre de connexions et alerter
if [ "$CONN_COUNT" -gt 1 ]; then
  echo "CRITICAL - $USER has $CONN_COUNT SSH connections"
  exit 2
else
  echo "OK - $USER has $CONN_COUNT SSH connections baby!!"
  exit 1
fi
Editor is loading...
Leave a Comment