Posted in Linux SSH
Log SSH connections with /etc/ssh/sshrc
Yannick over at http://blog.uggy.org always comes up with interesting and valuable tips.
Following his latest post regarding sshrc, I made my own sshrc script.
Unlike his example, I didn’t make SSH email me whenever a connection is made. That would be overkill given the number of connections I can make on a single day.
Instead I’m just logging dates and IP in a log file of its own, which I plan on keeping forever.
My /etc/ssh/sshrc :
DATE=`date "+%d.%m.%Y %Hh%Mm"`
IP=`echo $SSH_CONNECTION | awk '{print $1}'`
echo "$DATE - $IP" >> /var/log/ssh_connections.log
Comments
Sébastien Wains
They are binary files which means I need the last/lastlog command for the logs to be really useful. At some point I may want to just grab the log file using scp, which I can’t with last/lastlog, I need to run the commands to get the info.
Also last/lastlog logs get rotated by default.
It’s overall simpler, at least to me.
Goeldi
I use this on the third line:
echo “$DATE – $IP – $USER” >> /var/log/ssh_connections.log
Seb
By the way, I forgot to mention /var/log/ssh_connections.log must be writable by users able to SSH in.
sebastiaosantos
it’s a very simple, but is a good idea. i use to sent mail of connections.
Leave Comment
Please consider visiting the partners below if you enjoyed this article :If this post saved you time and money, please consider checking my Amazon wishlist.







Nitek
Why not using “last”/lastlog?