You are here: Home > Linux, Network, Tips&Info > Send email notification on successful ssh login using ssmtp

Send email notification on successful ssh login using ssmtp

Sometime i wants to know who is login and when user login to my server  but i don’t want to setup and run my own mail server, this can be done easily by using tcpwrapper and ssmtp , first make sure ssmtp is installed

# dpkg -l|grep ssmtp
iF  ssmtp                                  2.64-4fakesync1                                 extremely simple MTA to get mail off the sys


if ssmtp is not installed yet, install it by using

# apt-get install ssmtp


If you are using Gmail account , change the root, authuser, and authpass options to the email address, username, and password of your email account. If you’re using another mail service you’ll need to change mailhub to the relevant SMTP server.

edit /etc/ssmtp/ssmtp.conf and add these lines

FromLineOverride=YES # optional


Change the ‘From’ text by editing /etc/passwd to receive mail from ‘’ instead of just ‘root’.
# chfn -f root

edit /etc/ssmtp/revaliases and add this line or add more line for another user
# sSMTP aliases
# Format:    local_account:outgoing_address:mailhub
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.

to test it

# echo “test send email using ssmtp|mail -s “TEST”


once you are able to receive that test message, proceed to edit /etc/hosts.allow and add these 2 lines, so you will be notified if someone login to your sever

SSHD: ALL: spawn (/bin/echo "SSH connection to %H from %h[%a]" | \
/usr/bin/mail -s "SSH Login Alert []"



Tags: , ,

  • Digg
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Comments are closed.