> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# Email notification when someone logs in via SSH
- URL: https://til.codes/email-notification-when-someone-logs-in-via-ssh/
- Published: 2015-07-13T19:06:02.000Z
- Updated: 2015-07-13T19:06:22.000Z
- Author: Manu Ajith
- Tags: til, shell, email, ssh, alert, #Import 2024-07-13 21:01

To setup email notification, login to your server as root.

Edit `.bashrc`

```
vim .bashrc

```

add the following line at the end, changing `"ServerName"` to the host-name of your server and `"me@til.codes"` to your own email address.

```
echo 'ALERT - Root Shell Access (Server-name) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" me@til.codes

```

Save and exit.

Next time someone (hopefully you) logs on as root, you will get an email about this.