Monitoring & Update email notification via GMail on Ubuntu Linux Servers
System notification emails
Continuing in part off of my last Ubuntu Server article, "The Perfect Server", I decided that i wanted the server to send me emails updating its status with me. If the HD space gets low, the RAM is all used up, services go down, or even i lose internet at my house while im out and about, i get a nice email from my server notifying me of the problem (at least when my inet comes back online).
What better way to top this off than with use of a gmail account that i already owned and used?
In this article, i will walk you through installing the following along side your postfix installation:
Self signed SSL certfication (don't want anyone being nosey!)
Apticron - A nice set of scripts that will execute 'apt-get udpate' and email you the results
Webmin - One of the best web based management consoles for head-less servers. Has a great system notification setup, along with many many many other goodies.
Note: This how-to assumes you've already installed Postfix mail server on an Ubuntu Linux Server (sudo apt-get postfix)
1) Create a Certificate Authority
# sudo /usr/lib/ssl/misc/CA.pl -newca
Output:
CA certificate filename (or enter to create)
Making CA certificate …
Generating a 1024 bit RSA private key
…….++++++
……………….++++++
writing new private key to ‘./demoCA/private/cakey.pem’
Enter PEM pass phrase: password
Verifying – Enter PEM pass phrase: password
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [US]:US
State or Province Name (full name) [New York]:California
Locality Name (eg, city) []:Los Angeles
Organization Name (eg, company) []:TimAshley.me
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:Tim
Email Address []: tim@timashley.me
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/lib/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
2) Create a Server Certificate
# sudo openssl req -new -nodes -subj '/CN=domain.com/O=Sanborn_Widgets/C=US/ST=New York/L=New York/emailAddress=username@gmail.com' -keyout FOO-key.pem -out FOO-req.pem -days 3650
3) Sign the Certificate
# sudo openssl ca -out FOO-cert.pem -infiles FOO-req.pem
Output:
Using configuration from
/usr/lib/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
4) Copy the certificates to the Postfix directory
# sudo cp demoCA/cacert.pem FOO-key.pem FOO-cert.pem /etc/postfix
5) Change the permissions on the files
# sudo chmod 644 /etc/postfix/FOO-cert.pem /etc/postfix/cacert.pem
# sudo chmod 400 /etc/postfix/FOO-key.pem
6) Add GMail Certificate to /etc/postfix/cacert.pem
# sudo nano /etc/postfix/cacert.pem
Paste the following at the very bottom:
-----BEGIN CERTIFICATE-----
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy
dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t
MB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYTAlpB
MRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsG
A1UEChMUVGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRp
b24gU2VydmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNl
cnZlciBDQTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNv
bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2aovXwlue2oFBYo847kkE
VdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIhUdib0GfQ
ug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMR
uHM/qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG
9w0BAQQFAAOBgQAmSCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUI
hfzJATj/Tb7yFkJD57taRvvBxhEf8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JM
pAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7tUCemDaYj+bvLpgcUQg==
-----END CERTIFICATE-----
7) Relay your email through gmail
# sudo nano /etc/postfix/main.cf
Add: [smtp.gmail.com]:587
To: relayhost =
relayhost = [smtp.gmail.com]:587
!-Dont close the file yet, add TLS in the next step-!
8) Add TLS settings to Postfix
# sudo nano /etc/postfix/main.cf
Paste the following at the very bottom:
## TLS Settings
#
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_tls_cert_file = /etc/postfix/FOO-cert.pem
smtp_tls_key_file = /etc/postfix/FOO-key.pem
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/postfix/cacert.pem
smtpd_tls_cert_file = /etc/postfix/FOO-cert.pem
smtpd_tls_key_file = /etc/postfix/FOO-key.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
#
## SASL Settings
# This is going in to THIS server
smtpd_sasl_auth_enable = no
# We need this
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_local_domain = $myhostname
smtp_sasl_security_options = noanonymous
#smtp_sasl_security_options =
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd
transport_maps = hash:/etc/postfix/transport
!-Ok, now you can save ;)-!
9) Create a transport file
# sudo nano /etc/postfix/transport
Paste the following into the new file:
# Contents of /etc/postfix/transport
#
# This sends mail to Gmail
gmail.com smtp:[smtp.gmail.com]:587
#
10) Create the SASL password
# sudo nano /etc/postfix/sasl_passwd
Paste the following, replace username/password with your actual info:
#contents of sasl_passwd
#
[smtp.gmail.com]:587 username@gmail.com:password
11) Hash the password and transport files
# sudo postmap /etc/postfix/sasl_passwd
# sudo postmap /etc/postfix/transport
12) Reload Postfix
# sudo postfix reload
13) Restart Postfix services
# sudo /etc/init.d/postfix restart
14) Clean up the mess
# sudo rm FOO-req.pem FOO-cert.pem FOO-key.pem && sudo rm -r demoCA/
15) Send a test email
# echo "http://www.timashley.me 0wnz!!" | mail -s "Test" username@gmail.com
16) Install Apticron
# sudo apt-get install apticron
17) Configure apticron
# sudo nano /etc/apticron/apticron.conf
Enter your mail address in EMAIL=" "
18) Add Apticron to cron jobs
# crontab -e
Paste the following:
@daily /etc/cron.daily/apticron
19) System notifications
Install Webmin (Refer to "The Perfect Server" article)
You can add/remove/edit monitoring notifications in Others -> System and Server Status
Enjoy!
Teh haps'
Thu, 02/02/2012 - 19:52
Tim tweeted "@ThatKevinSmith Happy groundhog day! What's your 60 second review of the movie "Groundhogs Day"? #LIVEfrombehind" 7:52pm#
Tim tweeted "Jay and Silent Bob get old! (@ Edwards Renaissance Stadium 14 for Kevin Smith: Live from Behind w/ 2 others) [pic]: http://t.co/0k3NsmV5" 7:37pm#Mon, 01/30/2012 - 20:15
Tim tweeted "I had the pleasure of driving a giant circle around LA during rush hour with uber sore legs." 8:15pm#
Tim tweeted "Goggle tan FTW! :D" 11:16am#Sat, 01/28/2012 - 12:38
Tim tweeted "I'm at Mammoth Mountain Ski Resort (1 Minaret Rd, Mammoth Lakes) w/ 5 others http://t.co/SKvBroDM" 12:38pm#Fri, 01/27/2012 - 21:46
Tim tweeted "Mammoth bound!" 9:46pm#
Tim tweeted "I think I like burritos more than pizza now O_o (@ Baja Fresh) http://t.co/FtMOoGu8" 1:17pm#Thu, 01/26/2012 - 19:23
Tim tweeted "Just saw a "Veggie TDI" emblem on the back of a Jetta :D I wonder if they had to take out the turbo for the conversion." 7:23pm#
Tim tweeted "I just became the mayor of Candolyns Salon on @foursquare! http://t.co/El0GAvDM" 7:21pm#
Tim tweeted "I love meetings where I come out with a bonus :D" 11:29am#
Don't try to pass this guide off as your own when you clearly ripped it off from the blog it was published on more than a year ago.
PRO TIP: if you do decide to rip someone else off at least change the parameters in the certificate creation to reflect your info, not the original writers. i.e 'Sanborn Widgets'
- reply
Submitted by Anonymous on Wed, 04/07/2010 - 21:34.Never tried to pass any of this off on my own. It's tidbits from a number of blogs actually. I couldn't get it to work by just following one, hence why i posted what *DID* work for me. Should of taken that out of the cert request, my bad. If anything, the google bots will honor the keyword!
Enjoy the boost in ranking :)
- reply
Submitted by Tim Ashley on Fri, 04/09/2010 - 23:35.