How to enable SSH login notifications via email in CentOS 8

s2 0

This tutorial will show you how to enable email SSH login notifications in CentOS 8.

Is your Linux server being used by multiple users and you want to know when a user logs in via SSH? If so, you can enable SSH notifications in the bash profile to be notified. We’re going to add a little script that will send you an email when someone logs into the server.

Configure SSH login notification

To configure SSH login notification, open Terminal and open the file ~ / .bash_profile.

At the end of the file, add 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>

Substitute “Your email address“With the email in which you would like to receive an email. Save the file and exit.

diploma

In this tutorial we learned how to enable notification in CentOS 8 when a user accesses your Centos 8 server via SSH. It sends an email when the user accesses the system (date and time) and the IP address of the system from which the user is accessing the system.

How to enable SSH login notifications via email in CentOS 8