Pages

Search This Blog

Total Pageviews

Thursday, April 21, 2011

Removing old keys in your known_hosts file


If you happen to have changed server IP address and while at it you get this message doing a remote connnection:

ssh ants@192.168.1.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
eb:e8:de:47:00:77:2c:14:28:20:db:18:4c:9f:69:02.
Please contact your system administrator.
Add correct host key in /home/ants/.ssh/known_hosts to get rid of this message.
Offending key in /home/ants/.ssh/known_hosts:13
RSA host key for 192.168.1.1 has changed and you have requested strict checking.
Host key verification failed.

You will have to remove the entry by editing your known_hosts file. Remove the old entry, in this case its on line "13" save the file and try connecting again, accept the new one when prompted.

Done.

Learn IPTABLES and be Secure

Tuesday, April 19, 2011

Traceroute shell script for linux/unix

Before you run the below script you need to save server list in /tmp/servlist. The below mentioned bash script you need to put in crontab to run as per the schedule. This script will send the traceroute whenever node/server is down. Please comment if this script is useful for you.


#!/bin/bash
#Author : Tejas Vino
#Purpose : To send the traceroute whenever server/node is down.
#Version : V1.0
#Date :April 19, 2011

Hostname=`/bin/hostname`
Trace="/bin/traceroute -I"

for i in `cat /tmp/servlist`
do
test=`fping $i | grep unreachable | awk '{print $1'}`
echo $test
if [ -z "$test" ]; then
sleep 1
else
$Trace $test | mail -s "$test is Down!!! Traceroute from $Hostname to $test" youremailid@domain.com &
fi
done

Monday, April 18, 2011

Linux Foundation Is Celebrating 20 Years Of Linux - Are you ?

Linux is turning 20. And to commemorate this happy occasion, the Linux Foundation is celebrating 20 years of Linux with a slew of special events which includes Gala dinner, Video contest,a T-Shirt contest, Linux Scholarships et al.

The Linux Foundation has also released this nice infographic which depicts the major milestones of Linux development.

Sunday, April 17, 2011

free -m command in Linux


free -m is the most commonly used command to view memory usage in Linux. Output of free -m will look like this.

===============================================
-bash-3.2# free -m
                    total       used       free     shared    buffers     cached
Mem:           512        503          8          0         17        166
-/+ buffers/cache:       318       193
Swap:          511         95         416
================================================

Interpreting the output of free -m

As we can see, there are three rows Mem, buffers/cache & Swap.

(i) Mem:
  • 512 given under "total" indicates total 512MB of memory available in the server.
  • 503 given under "used" indicates current RAM usage. This number will be a number close to total RAM almost always since Linux will try to utilize spare memory to cache disk data.
  • 8 given under "free" is the amount of free memory available in the system.
  • 0 given under "shared" is the amount of memory shared between processes.
  • 17 given under "buffers" is the memory used for IO buffer.
  • 166 given under "cached" is the memory used for caching disk data.

(ii) buffers/cache
  • 318 given under "used" indicates memory used by running applications
  • 193 given under "free" is the total reclaimable memory. As I said earlier, Linux will try to utilize spare memory to cache disk data. But this memory used for cache can be very easily reclaimed by the OS for applications. Reclaimable memory will be roughly equal to buffers+cached+free, that is 17+166+8

(iii)Swap:
  • 511 given under "total" is total swap memory available in server.
  • 95  given under "used" is total swap memory used
  • 416 given under "free" is free swap memory available in server.

How it is calculated


Physically Used Memory = Actual used memory + buffers + cache = 318+17+166 = 501MB
Physically Free Memory = Total Physical Memory - Actual used memory - buffers - cache = 512-318-17-166 = 11MB
Memory free for Applications = Total Physical Memory - Actual used memory = 512-318 = 194MB
Memory used  by Applications = Physically Used Memory - buffers - cache = 501-17-166 = 318MB

Postfix Troubleshooting Guide

Problem. Connection Timeout error while sending mails.

Solution: First check your network connectvity & dns resolution
1. Please check your internet gateway is reachable or not with route -n & ping command
route -n
ping 172.26.3.94 ( Gateway IP Address)
ping google.com
2. Check your nameservers.
cat /etc/resolve.conf
search domainname.com
nameserver 4.2.2.2
nameserver 4.2.2.3
cat /etc/sysconfig/network
FORWARD_IPV4=yes
NETWORKING=yes
HOSTNAME=phtx
DOMAINNAME=domainname.com
3. Check your smtp port 25 is open or not with following command on your mail server.
telnet mail.domainname.com 25
4. Check your hosts file.
cat /etc/hosts
sample Output
127.0.0.1 localhost.localdomain localhost
192.168.0.1 domainname.com server
If You are using secondary mx pointer, so please check your secondary pointer ( Where your
mail server is located) is reachable or not with ping command
ping mail.domainname.com
--------------------------------------------------------------------------------------------------------------------------------
Problem : Access Denied Error (Relay access denied;)
 
Solution: First check your access file, from which ip address or domains your mails is being
relayed.
You can block or allow access for domain names or ip address here.
cat access
mail.domainname.com RELAY
64.229.18.84 RELAY
62.15.74.220 RELAY
As well as Please check mynetwork option in main.cf file
/etc/postfix/main.cf
mynetworks = 127.0.0.0/8, 225.57.0.0/24
-------------------------------------------------------------------------------------------------------------------------------------
Problem: User unknown error

Solution: If you are using virtual users, virtual domains , so please check your following
files.
/etc/postfix/virtual
/etc/postfix/canonical
as well as check your users in /etc/passwd file
make changes accordingly.
--------------------------------------------------------------------------------------------------------------------------------------
Problem: Host not found error

Solution: Please insert following option in main.cf file
File: /etc/postfix/main.cf
smtp_helo_name = server.domainname.com (hostname.domainname.com)
also check your domainname,hostname in /etc/hosts & /etc/sysconfig/network file.
--------------------------------------------------------------------------------------------------------------------------------------
Problem: Mail Bounce.

Solution: There may be various reason to mail bouce.
1. Hostname & domainname unreachable or dns problem ( The domain & host to which we are
sending mails), so please check the domain name or hostname with ping command.
--------------------------------------------------------------------------------------------------------------------------------------
Problem: Connection Dropped by IMAP server.

Solution: Please check dovecot service is running or not on the server.
/etc/init.d/dovecot status
cat /etc/dovecot.conf |grep protocol
protocols = imap imaps pop3 pop3s
--------------------------------------------------------------------------------------------------------------------------------------
Problem: Authentication Error or not authorised user error

Solution: If you are using secondary mx pointer ( mailing is hosted on another server),
then you’ve to maintain authentication credentials in /etc/postfix/sasl_passwd file
cat sasl_passwd
mail.domainname.com username@domainname.com:password
after that update database for sasl_passwd file
Note: whenever you make changes in following files, please update database of
respective file as following
if you make changes in acccess file , file path: /etc/postfix/access
so give postmap command with file name
postmap access
postmap virtual
postmap canonical
–------------------------------------------------------------------------------------------------------------------------------------

Postfix 2 with Dovecot Installation HOWTO

1. Install Postfix

=================================
yum install postfix
=================================

2. Install Dovecot


==================================
yum install dovecot
==================================

3. Remove Sendmail


==================================
yum remove sendmail
==================================

4. Enable Postfix & Dovecot on start up


==================================
chkconfig postfix on
chkconfig dovecot on
==================================


5. Configure Postfix


Postfix main configuration files are given below.
  • /etc/postfix/main.cf
  • /etc/postfix/master.cf

5.1 Configure main.cf


Open /etc/postfix/main.cf in an editor and make changes as explained below.

5.1.1 Set host name of the system.

=============================================
myhostname = mail.mailserver.com
=============================================

5.1.2 Set primary domain name of the server.

==================================
mydomain = mailserver.com
==================================

5.1.3 Specify source domain of locally generated emails


================================
myorigin = $myhostname
================================

5.1.4 Specify postfix listening interfaces

==================================
inet_interfaces = all
==================================

5.1.5 Add list of locally hosted domains


=========================================================================================
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
=========================================================================================

5.1.6 Add relay permitted IP addresses


===================================================
mynetworks = 127.0.0.0/8
===================================================

5.1.7 Add relay permitted IP addresses

Specify "mynetworks_style = host" since Postfix should "trust" only the local machine.

===================================================
mynetworks_style = host
===================================================

5.1.8 Add relay permitted domains.

This should be kept as blank.

==========================
relay_domains =
==========================

5.1.9 Configure Maildir as mailbox
================================
home_mailbox = Maildir/
================================

5.2 Configure Aliases


Create a user named "adminmails" to receive all administrator emails.

=================================
useradd adminmails;
=================================

Edit /etc/aliases

=====================================================
# Person who should get root's mail
root:             adminmails
postmaster:       adminmails
abuse:            adminmails
mailer-daemon:    adminmails
=====================================================

Create adminmails' maildir

==============================================
su - adminmails
mkdir ~/Maildir
chmod -R 700 ~/Maildir
==============================================

5.3 Configure sendmail soft-links

=================================================================
ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
ln -s  /usr/lib/sendmail.postfix /usr/lib/sendmail
=================================================================


6. Adding a user

6.1 Creating the user


=========================
useradd testusr
=========================

6.2 Setting password for the user

================================
passwd testusr
================================

6.3 Creating Maildir


========================================
su - testusr

mkdir ~/Maildir
chmod -R 700 ~/Maildir
========================================


7. Configure postfix as default mail server


7.1 Install system-switch-mail


============================================================
yum install system-switch-mail
============================================================

Now, run system-switch-mail command to configure postfix as default mail server



8. Start Postfix & Dovecot


============================================
/etc/init.d/postfix start
/etc/init.d/dovecot start
============================================


9. Setting up virtual domains
9.1 Setup email domain in /etc/postfix/virtual file


To setup virtual domains, we need to add domains & email addresses in /etc/postfix/virtual file

Edit /etc/postfix/virtual and add following contents.

===================================================
cptest.org              this-text-is-ignored
postmaster@cptest.org   postmaster
test1@cptest.org        cptest-test1
test2@cptest.org        cptest-test2
@cptest.org             cptest-test1
====================================================

This will setup the email domain cptest.org and two email addresses test1@cptest.org & test2@cptest.org.

Here, cptest-test1 & cptest-test2 are UNIX users. cptest-test1 is also configured as the catchall address for all cptest.org email addresses.

9.2 Creating the user

=========================
useradd cptest-test1
=========================

9.3 Setting password for the user


================================
passwd cptest-test1
================================

9.4 Creating Maildir

========================================
su - cptest-test1

mkdir ~/Maildir
chmod -R 700 ~/Maildir
========================================

9.5  Configure main.cf to use virtual domains

Edit /etc/postfix/main.cf and add following lines

======================================================================
virtual_alias_maps = hash:/etc/postfix/virtual
======================================================================

9.7 Create postfix virtual domains database

=========================================================
postmap /etc/postfix/virtual
=========================================================

9.8 Reload postfix

===========================================
/etc/init.d/postfix reload
===========================================

Thursday, April 14, 2011

Qmail with Dovecot Installation HOWTO

Note: This article doesn't cover all options of qmail installation & configuration. Please refer Life with qmail for a complete guide in qmail.

This howto was designed as a quick start or reference guide to a simple Qmail install. 

1. Qmail
qmail is a secure, reliable, efficient, simple message transfer agent. It is meant as a replacement for the entire sendmail-binmail system on typical Internet-connected UNIX hosts.

Secure: Security isn't just a goal, but an absolute requirement. Mail delivery is critical for users; it cannot be turned off, so it must be completely secure.

Reliable: qmail's straight-paper-path philosophy guarantees that a message, once accepted into the system, will never be lost. qmail also supports maildir, a new, super-reliable user mailbox format. Maildirs, unlike mbox files and mh folders, won't be corrupted if the system crashes during delivery. Even better, not only can a user safely read his mail over NFS, but any number of NFS clients can deliver mail to him at the same time.

Efficient: On a Pentium under BSD/OS, qmail can easily sustain 200000 local messages per day---that's separate messages injected and delivered to mailboxes in a real test! Although remote deliveries are  inherently limited by the slowness of DNS and SMTP, qmail overlaps 20 simultaneous deliveries by default, so it zooms quickly through mailing lists.

Simple: qmail is vastly smaller than any other Internet MTA. Some reasons why:

(1) Other MTAs have separate forwarding, aliasing, and mailing list mechanisms. qmail has one simple forwarding mechanism that lets users handle their own mailing lists.
(2) Other MTAs offer a spectrum of delivery modes, from fast+unsafe to slow+queued. qmail- send is instantly triggered by new items in the queue, so the qmail system has just one delivery mode: fast+queued.
(3) Other MTAs include, in effect, a specialized version of inetd that watches the load average.  qmail's design inherently limits the machine load, so qmail-smtpd can safely run from your system's inetd.

Replacement for sendmail: qmail supports host and user masquerading, full host hiding, virtual domains, null clients, list-owner rewriting, relay control, double-bounce recording, arbitrary RFC 822 address lists, cross-host mailing list loop detection, per-recipient checkpointing, downed host backoffs, independent message retry  schedules, etc. In short, it's up to speed on modern MTA features. qmail also includes a drop-in ``sendmail'' wrapper so that it will be  used transparently by your current UAs.

2. Required packages

There are four packages needed for this qmail install.
 
2.1 netqmail-1.06.tar.gz
qmail is a secure, reliable, efficient, simple message transfer agent. It is designed for typical Internet-connected UNIX hosts. As of October 2001, qmail is the second most common SMTP server on the Internet, and has by far the fastest growth of any SMTP server.

2.2 ucspi-tcp-0.88.tar.gz
It is a tool similar to inetd. ucspi-tcp listens in 25 port and spawns qmail-smtpd when required. ucspi-tcp stands for Unix Client Server Program Interface for TCP.

2.3 daemontools-0.76.tar.gz
daemontools is actually a tool to manage & monitor daemons linux. It is used in qmail as well to manage qmail daemons.

2.4 checkpassword-0.90.tar.gz
checkpassword provides a simple, uniform password-checking interface to all root applications. It is suitable for use by applications such as login, ftpd, and pop3d.

3. Qmail Install

3.1  Get the files

Download files and place them into the /usr/local/src directory.  This document refers to that directory for install procedures.

========================================================
cd /usr/local/src

wget http://www.qmail.org/netqmail-1.06.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz
=========================================================

Now create /package directory and move daemontools-0.76.tar.gz to /package.

=========================================================
mkdir /package
mv -iv /usr/local/src/daemontools-0.76.tar.gz /package
=========================================================

3.2 Create users and groups

Run following commands one by one, to create required users & groups

==============================================
groupadd nofiles
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
useradd -g nofiles -d /var/qmail/alias alias
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails
==============================================

3.3  Compile & Install

Untar the Qmail source

============================
cd /usr/local/src
tar -xzvf netqmail-1.06.tar.gz
===========================

Compile the source

===================================
cd /usr/local/src/netqmail-1.06
make setup check
===================================

4.  Configure Qmail

4.1 Post Installation setup


Post installation configuration can be done by running following script.

=============
./config;

==============

4.2 Configure Qmail aliases.

Create a user named "adminmails" to receive all administrator emails.

================================================
useradd adminmails;
cd ~alias;
echo "adminmails" > .qmail-postmaster;
echo "adminmails" > .qmail-mailer-daemon;
echo "adminmails" > .qmail-root;
echo "adminmails" > .qmail-postmaster;
echo "adminmails" > .qmail-abuse;
chmod 644 ~alias/.qmail* ;
==============================================

Create Maildir for "adminmails" user

========================================
su - adminmails
/var/qmail/bin/maildirmake ~/Maildir
========================================

4.3 Configure Qmail to use Maildir

Now we need to configure qmail to use the Maildir Format.

Create "/var/qmail/rc" with following contents.

====================================================================================
#!/bin/sh

# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"
=====================================================================================

Make "/var/qmail/rc" executable

============================
chmod 755 /var/qmail/rc
============================

Create "/var/qmail/control/defaultdelivery" file.

=====================================================
echo ./Maildir/ >/var/qmail/control/defaultdelivery
=====================================================

4.4 Replace Sendmail binaries

======================================================
chmod 0 /usr/lib/sendmail ;
chmod 0 /usr/sbin/sendmail ;
mv /usr/lib/sendmail /usr/lib/sendmail.bak ;
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak ;
ln -s /var/qmail/bin/sendmail /usr/lib/sendmail ;
ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
=======================================================

5.  Install ucspi-tcp


Untar the ucspi-tcp source.

=============================================================
cd /usr/local/src/
tar -xzvf ucspi-tcp-0.88.tar.gz
==============================================================

Patch ucspi-tcp with "ucspi-tcp-0.88.errno.patch" provided with net qmail.

==============================================================================
cd ucspi-tcp-0.88
patch < /usr/local/src/netqmail-1.06/other-patches/ucspi-tcp-0.88.errno.patch
===============================================================================

Install ucspi-tcp.

========================
make
make setup check
=========================

6. Install checkpassword


Untar checkpassword source.

=========================================
cd /usr/local/src
tar -xzvf checkpassword-0.90.tar.gz
=========================================

Patch checkpassword with "checkpassword-0.90.errno.patch" provided with net qmail.

================================================================
cd checkpassword-0.90
patch < /usr/local/src/netqmail-1.06/other-patches/checkpassword-0.90.errno.patch
================================================================

Install checkpassword.

==================================
make ;
make setup check
==================================

7. Install daemontools

Untar the daemontools source

=========================================
cd /package
tar -xzvf daemontools-0.76.tar.gz
=========================================

Patch daemontools with "daemontools-0.76.errno.patch" provided with net qmail.

=========================================================================
cd /package/admin/daemontools-0.76/src
patch < /usr/local/src/netqmail-1.06/other-patches/daemontools-0.76.errno.patch
=========================================================================

Install daemontools

====================
cd ..
package/install
====================

8. Qmail Startup script

The "qmailctl" script is used as startup script for qmail.

8.1 Download qmailctl

===========================================================
cd /var/qmail/bin/
wget http://lifewithqmail.org/qmailctl-script-dt70
===========================================================

8.2 Setup qmailctl

========================================
mv -iv qmailctl-script-dt70 qmailctl
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
========================================


9. Setup qmail-send & qmail-smtpd

9.1 Create supervise script directories for qmail daemons

Create supervise directories for qmail-send, qmail-smtpd & qmail-pop3d.

======================================================
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir  -p /var/qmail/supervise/qmail-pop3d/log
======================================================

9.2 Create supervise script for qmail-send

Create supervise script for qmail-send with name "/var/qmail/supervise/qmail-send/run".

The file should have following contents.

====================
#!/bin/sh
exec /var/qmail/rc
====================

9.3 qmail-send log daemon supervise script

Create qmail-send log daemon supervise script with name "/var/qmail/supervise/qmail-send/log/run".

The script should have following contents

======================================================================================
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
======================================================================================

9.4 qmail-smtpd daemon supervise script

Create qmail-smtpd daemon supervise script with name "/var/qmail/supervise/qmail-smtpd/run".

The script should have following contents

=========================================================================================
#!/bin/sh

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`

if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
    echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
    echo /var/qmail/supervise/qmail-smtpd/run
    exit 1
fi

if [ ! -f /var/qmail/control/rcpthosts ]; then
    echo "No /var/qmail/control/rcpthosts!"
    echo "Refusing to start SMTP listener because it'll create an open relay"
    exit 1
fi

exec /usr/local/bin/softlimit -m 9000000 \
    /usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
==========================================================================================

Create the concurrencyincoming control file.

======================================================
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
======================================================

9.5 qmail-smtpd log daemon supervise script

Create qmail-smtpd log daemon supervise script with name "/var/qmail/supervise/qmail-smtpd/log/run".

The script should have following contents

========================================================================================
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
========================================================================================

9.6 Create the  log directories and add execute permissions on the run scripts.

=====================================================
mkdir -p /var/log/qmail/smtpd

chown qmaill /var/log/qmail
chown qmaill /var/log/qmail/smtpd

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run

chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

======================================================

10. Create soft link for the daemons in /service folder

10.1  Add qmail-send  to /service folder


=================================================================
ln -s /var/qmail/supervise/qmail-send /service/qmail-send
=================================================================

10.2  Add qmail-smtpd to /service folder

===================================================================
ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd
===================================================================


Note 1: The /service directory is created when daemontools is installed.

Note 2: The qmail system will start automatically shortly after these links are created.

If you don't want it running now, do: qmailctl stop


11. Configuring Dovecot

11.1 Install dovecot

====================
yum install dovecot
====================

11.2 Start dovecot

==============================
/etc/init.d/dovecot start
==============================

12. Adding a user

12.1 Creating the user

=========================
useradd testusr
=========================

12.2 Setting password for the user

================================
passwd testusr
================================

12.3 Creating Maildir

========================================
su - testusr
/var/qmail/bin/maildirmake ~/Maildir
========================================

13. Adding virtual domain users


13.1 Add entry in virtualdomains
Add following line to /var/qmail/control/virtualdomains file.

========================
example.com:example
========================

13.2 Add entry in rcpthosts

Add example.com in /var/qmail/control/rcpthosts file.

Please ensure that example.com is not added in /var/qmail/control/locals file


13.3 Add "example" user to accept example.com emails

"example" is a master user for the virtual domain example.com. This master user will control all mails of the virtual domain.

Create "example" as a local user.

=====================
useradd example
passwd example
=====================

13.4 Setting up maildir for "example"

su as "example"

=========================
su - example
=========================

Create maildir

======================================
/var/qmail/bin/maildirmake ~/Maildir
======================================

13.5 Configure "example" to accept example.com emails

Create the file .qmail-default file.

===========================
touch .qmail-default
===========================

13.5 Restart Qmail

Now, we have to restart qmail to take effect the settings

================================
qmailctl stop
qmailctl start
================================

Local user "example" will now accept emails for all users at example.com(Eg: test@example.com, postmaster@example.com etc).

13.6 Creating more users in example.com

Create user test1

=================
useradd test1
passwd test1
================

Now su as "test1"

=================
su - test1
=================

Create maildir

======================================
/var/qmail/bin/maildirmake ~/Maildir
======================================

Now exit from "test1" shell

Now su as "example"

========================
su - example
========================

Create ".qmail-test1" with following contents

=========
&test1
=========

13.7 Restart Qmail

Now, we have to restart qmail to take effect the settings

================================
qmailctl stop
qmailctl start
================================

Now, test1@example.com will be delivered to the maildir of "test1".


Reference
1. http://tac-au.com/howto/qmail-mini-HOWTO.txt
2. http://www.lifewithqmail.org/lwq.html

Important Notice
1. Rights to portions in red colour belongs to Life with qmail and those portions are licensed under OpenContent License, version 1.0.
2. This article as a whole is also licensed under OpenContent License, version 1.0.
3. See http://www.opencontent.org/opl.shtml for the full license.

Net Qmail Installation HOWTO

Note: This article doesn't cover all options of qmail installation & configuration. Please refer Life with qmail for a complete guide in qmail.

This howto was designed as a quick start or reference guide to a simple Qmail install. 

1. Qmail
qmail is a secure, reliable, efficient, simple message transfer agent. It is meant as a replacement for the entire sendmail-binmail system on typical Internet-connected UNIX hosts.

Secure: Security isn't just a goal, but an absolute requirement. Mail delivery is critical for users; it cannot be turned off, so it must be completely secure.

Reliable: qmail's straight-paper-path philosophy guarantees that a message, once accepted into the system, will never be lost. qmail also supports maildir, a new, super-reliable user mailbox format. Maildirs, unlike mbox files and mh folders, won't be corrupted if the system crashes during delivery. Even better, not only can a user safely read his mail over NFS, but any number of NFS clients can deliver mail to him at the same time.

Efficient: On a Pentium under BSD/OS, qmail can easily sustain 200000 local messages per day---that's separate messages injected and delivered to mailboxes in a real test! Although remote deliveries are  inherently limited by the slowness of DNS and SMTP, qmail overlaps 20 simultaneous deliveries by default, so it zooms quickly through mailing lists.

Simple: qmail is vastly smaller than any other Internet MTA. Some reasons why:

(1) Other MTAs have separate forwarding, aliasing, and mailing list mechanisms. qmail has one simple forwarding mechanism that lets users handle their own mailing lists.
(2) Other MTAs offer a spectrum of delivery modes, from fast+unsafe to slow+queued. qmail- send is instantly triggered by new items in the queue, so the qmail system has just one delivery mode: fast+queued.
(3) Other MTAs include, in effect, a specialized version of inetd that watches the load average.  qmail's design inherently limits the machine load, so qmail-smtpd can safely run from your system's inetd.

Replacement for sendmail: qmail supports host and user masquerading, full host hiding, virtual domains, null clients, list-owner rewriting, relay control, double-bounce recording, arbitrary RFC 822 address lists, cross-host mailing list loop detection, per-recipient checkpointing, downed host backoffs, independent message retry  schedules, etc. In short, it's up to speed on modern MTA features. qmail also includes a drop-in ``sendmail'' wrapper so that it will be  used transparently by your current UAs.

2. Required packages

There are four packages needed for this qmail install.
 
2.1 netqmail-1.06.tar.gz
qmail is a secure, reliable, efficient, simple message transfer agent. It is designed for typical Internet-connected UNIX hosts. As of October 2001, qmail is the second most common SMTP server on the Internet, and has by far the fastest growth of any SMTP server.

2.2 ucspi-tcp-0.88.tar.gz
It is a tool similar to inetd. ucspi-tcp listens in 25 port and spawns qmail-smtpd when required. ucspi-tcp stands for Unix Client Server Program Interface for TCP.

2.3 daemontools-0.76.tar.gz
daemontools is actually a tool to manage & monitor daemons linux. It is used in qmail as well to manage qmail daemons.

2.4 checkpassword-0.90.tar.gz
checkpassword provides a simple, uniform password-checking interface to all root applications. It is suitable for use by applications such as login, ftpd, and pop3d.

3. Qmail Install

3.1  Get the files

Download files and place them into the /usr/local/src directory.  This document refers to that directory for install procedures.

========================================================
cd /usr/local/src

wget http://www.qmail.org/netqmail-1.06.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz
=========================================================

Now create /package directory and move daemontools-0.76.tar.gz to /package.

=========================================================
mkdir /package
mv -iv /usr/local/src/daemontools-0.76.tar.gz /package
=========================================================

3.2 Create users and groups

Run following commands one by one, to create required users & groups

==============================================
groupadd nofiles
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
useradd -g nofiles -d /var/qmail/alias alias
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails
==============================================

3.3  Compile & Install

Untar the Qmail source

============================
cd /usr/local/src
tar -xzvf netqmail-1.06.tar.gz
===========================

Compile the source

===================================
cd /usr/local/src/netqmail-1.06
make setup check
===================================

4.  Configure Qmail

4.1 Post Installation setup


Post installation configuration can be done by running following script.

=============
./config;

==============

4.2 Configure Qmail aliases.

Create a user named "adminmails" to receive all administrator emails.

================================================
useradd adminmails;
cd ~alias;
echo "adminmails" > .qmail-postmaster;
echo "adminmails" > .qmail-mailer-daemon;
echo "adminmails" > .qmail-root;
echo "adminmails" > .qmail-postmaster;
echo "adminmails" > .qmail-abuse;
chmod 644 ~alias/.qmail* ;
==============================================

Create Maildir for "adminmails" user

========================================
su - adminmails
/var/qmail/bin/maildirmake ~/Maildir
========================================


4.3 Configure Qmail to use Maildir

Now we need to configure qmail to use the Maildir Format.

Create "/var/qmail/rc" with following contents.

====================================================================================
#!/bin/sh

# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"
=====================================================================================

Make "/var/qmail/rc" executable

============================
chmod 755 /var/qmail/rc
============================

Create "/var/qmail/control/defaultdelivery" file.

=====================================================
echo ./Maildir/ >/var/qmail/control/defaultdelivery
=====================================================

4.4 Replace Sendmail binaries

======================================================
chmod 0 /usr/lib/sendmail ;
chmod 0 /usr/sbin/sendmail ;
mv /usr/lib/sendmail /usr/lib/sendmail.bak ;
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak ;
ln -s /var/qmail/bin/sendmail /usr/lib/sendmail ;
ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
=======================================================

5.  Install ucspi-tcp


Untar the ucspi-tcp source.

=============================================================
cd /usr/local/src/
tar -xzvf ucspi-tcp-0.88.tar.gz
==============================================================

Patch ucspi-tcp with "ucspi-tcp-0.88.errno.patch" provided with net qmail.

==============================================================================
cd ucspi-tcp-0.88
patch < /usr/local/src/netqmail-1.06/other-patches/ucspi-tcp-0.88.errno.patch
===============================================================================

Install ucspi-tcp.

========================
make
make setup check
=========================

6. Install checkpassword


Untar checkpassword source.

=========================================
cd /usr/local/src
tar -xzvf checkpassword-0.90.tar.gz
=========================================

Patch checkpassword with "checkpassword-0.90.errno.patch" provided with net qmail.

================================================================
cd checkpassword-0.90
patch < /usr/local/src/netqmail-1.06/other-patches/checkpassword-0.90.errno.patch
================================================================

Install checkpassword.

==================================
make ;
make setup check
==================================

7. Install daemontools

Untar the daemontools source

=========================================
cd /package
tar -xzvf daemontools-0.76.tar.gz
=========================================

Patch daemontools with "daemontools-0.76.errno.patch" provided with net qmail.

=========================================================================
cd /package/admin/daemontools-0.76/src
patch < /usr/local/src/netqmail-1.06/other-patches/daemontools-0.76.errno.patch
=========================================================================

Install daemontools

====================
cd ..
package/install
====================

8. Qmail Startup script

The "qmailctl" script is used as startup script for qmail.

8.1 Download qmailctl

===========================================================
cd /var/qmail/bin/
wget http://lifewithqmail.org/qmailctl-script-dt70
===========================================================

8.2 Setup qmailctl

========================================
mv -iv qmailctl-script-dt70 qmailctl
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
========================================

8.3 Modify qmailctl for qmail-pop3d

Add following lines to qmailctl's "start" section.

========================================================================
    if svok /service/qmail-pop3d ; then
      svc -u /service/qmail-pop3d /service/qmail-pop3d/log
    else
      echo qmail-pop3d supervise not running
    fi
========================================================================

Add following lines to qmailctl's "stop" section.

======================================================================
    echo "  qmail-pop3d"
    svc -d /service/qmail-pop3d /service/qmail-pop3d/log
======================================================================

Add following lines to qmailctl's "stat" section.

=======================================
    svstat /service/qmail-pop3d
    svstat /service/qmail-pop3d/log
=======================================

Add the following lines to qmailctl's "pause" section.

=======================================
    echo "Pausing qmail-pop3d"
    svc -p /service/qmail-pop3d
=======================================

Add following lines to qmailctl's "cont" section.

=======================================
    echo "Continuing qmail-pop3d"
    svc -c /service/qmail-pop3d
=======================================

Add following lines to qmailctl's "restart" section.

=========================================================
    echo "* Restarting qmail-pop3d."
    svc -t /service/qmail-pop3d /service/qmail-pop3d/log
=========================================================


9. Setup qmail-send & qmail-smtpd

9.1 Create supervise script directories for qmail daemons

Create supervise directories for qmail-send, qmail-smtpd & qmail-pop3d.

======================================================
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir  -p /var/qmail/supervise/qmail-pop3d/log
======================================================

9.2 Create supervise script for qmail-send

Create supervise script for qmail-send with name "/var/qmail/supervise/qmail-send/run".

The file should have following contents.

====================
#!/bin/sh
exec /var/qmail/rc
====================

9.3 qmail-send log daemon supervise script

Create qmail-send log daemon supervise script with name "/var/qmail/supervise/qmail-send/log/run".

The script should have following contents

======================================================================================
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
======================================================================================

9.4 qmail-smtpd daemon supervise script

Create qmail-smtpd daemon supervise script with name "/var/qmail/supervise/qmail-smtpd/run".

The script should have following contents

=========================================================================================
#!/bin/sh

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`

if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
    echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
    echo /var/qmail/supervise/qmail-smtpd/run
    exit 1
fi

if [ ! -f /var/qmail/control/rcpthosts ]; then
    echo "No /var/qmail/control/rcpthosts!"
    echo "Refusing to start SMTP listener because it'll create an open relay"
    exit 1
fi

exec /usr/local/bin/softlimit -m 9000000 \
    /usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
==========================================================================================

Create the concurrencyincoming control file.

======================================================
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
======================================================

9.5 qmail-smtpd log daemon supervise script

Create qmail-smtpd log daemon supervise script with name "/var/qmail/supervise/qmail-smtpd/log/run".

The script should have following contents

========================================================================================
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
========================================================================================

9.6  qmail-pop3d daemon supervise script

Create qmail-pop3d daemon supervise script with name "/var/qmail/supervise/qmail-pop3d/run" .

The script should have contents.

=================================================================================
#!/bin/sh
exec /usr/local/bin/softlimit -m 9000000 \
    /usr/local/bin/tcpserver -v -R -H -l 0 0 110 /var/qmail/bin/qmail-popup \
        FQDN /bin/checkpassword /var/qmail/bin/qmail-pop3d Maildir 2>&1
=================================================================================

Please replace FQDN with fully qualified domain name of the POP server
E.g: pop.example.com

9.7 qmail-pop3d log daemon supervise script

Create qmail-pop3d log daemon supervise script with name "/var/qmail/supervise/qmail-pop3d/log/run".

The script should have following contents

====================================================================
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t \
    /var/log/qmail/pop3d
====================================================================

9.8 Create the  log directories and add execute permissions on the run scripts.

=====================================================
mkdir -p /var/log/qmail/smtpd
mkdir /var/log/qmail/pop3d

chown qmaill /var/log/qmail
chown qmaill /var/log/qmail/smtpd
chown qmaill /var/log/qmail/pop3d

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run

chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run
======================================================

10. Create soft link for the daemons in /service folder

10.1  Add qmail-send  to /service folder


=================================================================
ln -s /var/qmail/supervise/qmail-send /service/qmail-send
=================================================================

10.2  Add qmail-smtpd to /service folder

===================================================================
ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd
===================================================================

10.3 Add qmail-pop3d in /service folder.

=====================================================================
ln -s /var/qmail/supervise/qmail-pop3d /service/qmail-pop3d
=====================================================================

Note 1: The /service directory is created when daemontools is installed.

Note 2: The qmail system will start automatically shortly after these links are created.

If you don't want it running now, do: qmailctl stop



Reference
1. http://tac-au.com/howto/qmail-mini-HOWTO.txt
2. http://www.lifewithqmail.org/lwq.html

Important Notice
1. Rights to portions in red colour belongs to Life with qmail and those portions are licensed under OpenContent License, version 1.0.
2. This article as a whole is also licensed under OpenContent License, version 1.0.
3. See http://www.opencontent.org/opl.shtml for the full license.