Article

Table of Contents
Theme:
Was this article helpful?

0  out of  1 found this helpful

Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Enable SSH Login Notification on Linux

Last Updated: Tue, Sep 30, 2014
CentOS Debian Linux Guides Ubuntu

Is your Linux server accessed by multiple users? If so, consider adding an SSH login notification whenever someone logs in.

The examples below send an email when someone logs into your server. For this to work, your server must be able to send mail using the mail command. You may follow this tutorial to setup Exim with Gmail if your VULTR account is not verified to send mail.

Replace YOUR_EMAIL_ADDRESS with the email address that you want to receive login notifications.

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

Want to contribute?

You could earn up to $600 by adding new articles.