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`" example@example.com
in the .bashrc
.
Why I don't receive any emails?
Thank you for your help, J
.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
精彩评论