Linux send an email after login

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

10 ÷ = 5