I want to make sure everytime someone is login into my server I receive an email saying:
ALERT Shell Access on: Tue Jun 16 11:04:10 CDT 2009 user123 pts/0 2009-06-16 11:04
So I put this code:
echo 'ALERT Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]
in the .bashrc
.
Why I don't receive any emails?
Thank you for your help, J
How to create an SSH login alert. Where EMAIL is the email address you want the alerts sent to. Save and close the file. Log out and log back into the system with SSH and you should eventually see an email alert to the destination email address of the login.
.bashrc is executed when bash is run as a interactive non-login shell, which is not the case when you ssh. Add the same code in .bash_profile which should be run when the shell is a login shell
Note: Many distributions source .bashrc from .bash_profile, I may be wrong and the issue may not be about .bashrc / .bash_profile
Add into /etc/ssh/sshrc
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
logger -t ssh-wrapper $USER login from $ip
msg="User $USER just logged in from $ip"
echo $msg|mail -s $msg root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With