OpenBSD and smtpd

Published: 30 januari 2012 | Category: General, Hints, Security | Labels: , , | Short url » | Be the first to comment! »

Finally there is a secure and easy-to-configurate substitute for ”Sendmail”, ”OpenSMTPD”!

OpenSMTPD (smtpd) first appeared in OpenBSD 4.6 and will probably replace sendmail as the default mail daemon in OpenBSD 5.1. With this in mind, I replased sendmail with smtpd when I upgraded my OpenBSD (4.8 to 5.0) routers/gateways a few weeks ago. Since they only send ”cron” emails there are not much traffic to talk about but it still feels great to finally replace the old dusty Sendmail.

Here are the steps I went through to get started with smtpd. For a reference see the maual pages at OpenSMTPD.org.

smtpd is not enabled by default. In order to use it as the system
mailer, ensure the mail queue is empty, then stop sendmail(8):

# pkill sendmail

Modify the current mailwrapper(8) settings by editing /etc/mailer.conf:

# cat /etc/mailer.conf
sendmail /usr/sbin/smtpctl
send-mail /usr/sbin/smtpctl
mailq /usr/sbin/smtpctl
makemap /usr/libexec/smtpd/makemap
newaliases /usr/libexec/smtpd/makemap

Rebuild the aliases database, and enable the daemon to run at boot:

# newaliases

# echo ”sendmail_flags=NO” >> /etc/rc.conf.local
# echo ”smtpd_flags=” >> /etc/rc.conf.local

The above parts was all taken from the manuals so here comes the parts that differs depending on the purpose with smtpd. My purpose is to accept outgoing mail from localhost (lo0) only and relay them through my Loopia email account using TLS authentication on port 587. More examples and informations can be found at calomel.org.

# cat /etc/mail/smtpd.conf
listen on 127.0.0.1 port 25
expire 4h
hostname my.local.domain
map ”aliases” { source db ”/etc/mail/aliases.db” }
map ”secrets” { source db ”/etc/mail/secrets.db” }
accept from local for local alias aliases deliver to mbox
accept from local for all relay via mailcluster.loopia.se port 587 tls auth ”secrets”

Since the mailserver uses authentication the username and password is saved in a separate file with restricted permissions.

# cat /etc/mail/secrets
mailcluster.loopia.se LOOPIA_USERNAME@mydomain.tld:LOOPIA_PASSWORD

# chmod 640 /etc/mail/secrets
# chown root:_smtpd /etc/mail/secrets

# cd /etc/mail
# makemap /etc/mail/secrets

Check the config for errors and start smtpd in the background.

# smtpd -n
configuration OK

# smtpd

See so it is working by sending an email to a local user or root depending on your  /etc/mail/aliases setup.

# smtpctl show stats | grep ‘mta.sessions=’

# echo ”A test message” | mail -s ”Subject” root

# smtpctl show stats | grep ‘mta.sessions=’


Email on successful login

Published: 17 december 2011 | Category: Hints, Security | Labels: , , | Short url » | Be the first to comment! »

If you have a server that you know nobody really should login to, it can be a good idea to track the few logins the server gets. I have done this on my OpenBSD router by telling /etc/profile (who runs on every login) to send me an email about every successful login. The line I added to /etc/profile looks like this:

echo -e ”Login on `hostname` `date` \n\n# w $(whoami)\n`w $(whoami)` \n\n# who -HTu\n`who -HTu`” | mail -s ”Login on `hostname` as (`whoami`)” root

What this do is that it collect some useful information about the user that has just logged in and sends an email to the root user. If you do not have set up an alias for the user it is possible to change ”root” in the command above to an email address. The email will look like:

Subject: Login on gw.localdomain as (username)

Login on gw.localdomain Sat Dec 17 12:04:17 CET 2011

# w username
12:04PM  up  2:37, 1 user, load averages: 0.40, 0.77, 0.90
USER    TTY FROM              LOGIN@  IDLE WHAT
username   p0 192.168.0.22    12:04PM     0 w username

# who -HTu
USER     S LINE     WHEN         IDLE    FROM
username   + ttyp0    Dec 17 12:04   .     (192.168.0.22)


Min MacBook gillar Seagate

Published: 18 januari 2011 | Category: Hints | Labels: , , , , , | Short url » | Be the first to comment! »

Har sedan tidigare bytt ut ramminnet i min MacBook 3,1 och nu var det dags att byta hårddisk. Lyckligtvis fick jag en disk av min älskade flickvän och sambo i julklapp. Disken var den omtalade Seagate Momentus 7200.4 500GB (ST9500420AS) utan deras egen fallsensor då MacBooken har en egen inbyggd fallsensor som inte alltid syncar med andra fallsensorer.

Orsaken till att den är så omtalad är just problemet med fallsensorn men även att den ska ha problem med ”klickljud” och ha svårt att hantera stora dataströmmar. Jag har genomfört tester med stora dataströmmar och det har fungerat kanonbra, inte heller hörs några ”klickljud”. En möjlig orsak till problemen kan vara någon firmware eller drivrutin som inte vart på topp som nu tycks vara löst. Alla test gjordes med MacOS X 10.6.6.

Måste även passa på att ge DustinHome en stor eloge för sina kanonbra studentpriser och snabba leveranser!


Tävling

Published: 13 juli 2010 | Category: Hints | Labels: , , , | Short url » | One Comment »

Sugen på en ny bil?

Var med och tävla på tavling.loopia.se! Allt du behöver göra är en liten reklamfilm på 15-30s. Andrapriset är en laptop och 3-5pris är en iPad, inte mycket att vänta på med andra ord! Läs mer på bloggen.


Bloglovin, Huu?

Published: 21 mars 2010 | Category: Hints | Labels: , | Short url » | Be the first to comment! »

Oj, nu blev jag visst med på Bloglovin… Följ min blogg med bloglovin!