原理:~/.bashrc 文件为登录后默认自动执行的脚本。
CentOS
Open the file ~/.bash_profile in a text editor.
Append the following lines:
IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"HOSTNAME=$(hostname)NOW=$(date +"%e %b %Y, %a %r")
echo 'Someone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | mail -s 'SSH Login Notification' YOUR_EMAIL_ADDRESS
Ubuntu/Debian
Open the file ~/.bashrc in a text editor.
Append the following lines:
IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"HOSTNAME=$(hostname)NOW=$(date +"%e %b %Y, %a %r")
echo 'Someone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | mail -s 'SSH Login Notification' YOUR_EMAIL_ADDRESS
可以 发送到 139邮箱等短信通知邮箱,实现短信通知功能。
