Does anyone have a bash script that will email or notify someone in the case of a successful login to a ssh server? I want to be notified if anyone logs into my personal box.
I'm using Ubuntu 12.04 running xfce
Warning: according to the comments, this does not work if the user creates a file called
Modify or create
This will effectively notify you by email anytime someone logs in through SSH, and the login will be logged in the syslog.
Note: You'll need the
Note: works with port forwarding, but with -N option not.
First you need to be able to send mail from the command line. There are other questions about this. On a mail server it's probably easiest to install
Then you need an executable script file
Once you have that, you can add the following line to
For testing purposes, the module is included as
For those of you in need of an explanation of what PAM is and how it works, here is a very good one.
Note: The mailserver configuration, email format etc. should be set in
Update: Wrote a more detailed blog post on this
Put the following in
How the script works
Next, we then build the text of the message:
Summary Linux will, by default, record every system login, whether by ssh or not, in the system log files, but sometimes – particularly for a system that is seldom accessed via ssh – a quick and dirty notification can be useful.