It is a security concept that you know when a user (almost root user) loge in.
For this do like below
Add a shell script to send email
cd etc/ssh/
nano login-notify.sh
and add below code
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/sh # Change these two lines: if [ "$PAM_TYPE" != "close_session" ]; then host="`hostname`" subject="SSH Login: $PAM_USER from $PAM_RHOST on $host" # Message to send, e.g. the current environment variables. message="`env`" echo "$message" | mail "$sender" -s "$subject" "$recepient" fi |
You should change sender
and recepient
After that we should change file permission chmod a+w login-notify.sh
and for testing sh login-notify.sh
Please check your email (inbox and spam folder).
nano /etc/pam.d/sshd
And add this line at the end of file (use Alt and / to go to the end)
session optional pam_exec.so seteuid /path/to/login-notify.sh
All thing is ready but be careful, Please use another terminal to connect to your server and do not close your current connection.