Email or SMS alert / notification on SSH login using PHP script

Get Email or SMS notification on SSH login with PHP script using these instructions

Create a new file called sshrc in /etc/ssh/
Paste these commands:
#!/bin/sh
TEXT="$(date): ssh login to ${USER}@$(hostname -f)"
TEXT="$TEXT from $(echo $SSH_CLIENT|awk '{print $1}')"
/usr/bin/php /var/www/yourdomain.com/ssh-login-alert.php "$TEXT"

Then in your PHP script
< ?php
$arg1 = $argv[1];
mail("someone@example.com","[SMS] SSH Login", "SSH Login notification: $arg1");
? >

Now you will receive an email every time someone logs in to your SSH server. If you also want to receive SMS message create a filter in your gmail account using [SMS] in the subject line and forward it to your phone as 5555555555@yourphonecompany.com.

❮ Back to blog