• Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
all links
  • How to log history and logins from multiple ssh-keys under one user account | Screenage

    Une astuce utile pour faire un audit des connexions par clé sur un compte (quand on a plusieurs personnes avec des clés différentes qui accèdent au meme user)

    Implémentation rapide :

    !/bin/bash

    On convertit le authorized_keys pour ajouter la variable d'env

    cp ~/.ssh/authorized_keyz ~/.ssh/authorized_keyz.ORIGINAL

    IFS=$'\n'
    for line in $(cat .ssh/authorized_keys)
    do
    comment=$(echo $line|cut -d' ' -f3)
    echo "environment=\"SSH_USER=$comment\" $line" >> ~/.ssh/authorized_keyz.COMMENT
    done

    cp ~/.ssh/authorized_keyz.COMMENT ~/.ssh/authorized_keyz

    Puis dans le bashrc de l'user, ajouter ça :

    if [ "$SSH_USER" != "" ]; then
    now=$(date +%Y-%m-%d_%H-%M-%S)
    echo $now : User $SSH_USER logged in >> ~/ssh-audit.log
    fi

    May 14, 2014 - permalink - http://www.screenage.de/blog/2012/02/10/how-to-log-history-and-logins-from-multiple-ssh-keys-under-one-user-account-with-puppet/
    audit ssh