Menu

Results for category "Uncategorized"

7 Articles

QUICK-N-DIRTY GUIDE TO USING OPENSSH KEYPAIR AUTHENTICATION

To generate a keypair, run:

ssh-keygen -t dsa

(you are advised not to protect the key with a password, as you will then be
prompted for the password everytime you connect). The keypair will be saved
(by default) in $HOME/.ssh/id_dsa, and $HOME/.ssh/id_dsa.pub (the .pub file
is the public key, and the other is the corresponding private key). Now, set
the permissions to protect your $HOME/.ssh/ directory. (Note that these modes
are the most lax permissions that these files and directories are allowed to 
have. You may certainly set the permissions stricter.)

chmod 711 $HOME/
chmod 700 $HOME/.ssh/
chmod 644 $HOME/.ssh/*
chmod 600 $HOME/.ssh/id_dsa

Finally, add the public key to the $HOME/.ssh/authorized_keys file on each
machine to which you wish to connect and set the correct permissions. (Note
that you will be prompted for a password with each command. An alternative is
to login to server and run the commands locally. If you do so, remove the
quoting from the rightmost arguments.)

cat $HOME/.ssh/id_dsa.pub server 'cat >>.ssh/authorized_keys'
ssh server chmod 711 "$HOME/"
ssh server chmod 700 "$HOME/.ssh"
ssh server chmod 644 "$HOME/.ssh/authorized_keys"

For each machine you want to be able to connect from, first copy the id_dsa
file (the private key) to that machine, then follow the above steps.

The Quick-N-Dirty Guide to ssmtp

The aim of this QND guide is to get you up and running quickly with ssmtp. There will be far more how than why here.

The ssmtp program is designed to be a substitute for sendmail (or postfix, exim and other heavy duty MTA’s) for people who need an external smtp program to send mail, such as those who use mutt. While it is slightly more complex and heavy than nbsmtp (no brainer smtp) it is a bit more efficient, writes to /var/log/maillog and has a few nice features.

1.) Do you have ssmtp?

I don’t know of any Linux distro or other *nix system that installs ssmtp by default. However, it never hurts to check. At a command line type

which ssmtp

If you get a response like /usr/bin/ssmtp or /usr/local/sbin/ssmtp, you can skip to step 3. Otherwise, continue with step 2.

2.)Installing

First follow the instructions in the QND software guide for information on getting and installing ssmtp. If it’s not included with your distribution (while it is in Gentoo’s portage and FreeBSD’s ports, it doesn’t seem to be on any of the RedHat 8.0 CD’s) then go to the homepage. They have a tar.gz file.

3.)Installing ssmtp

FreeBSD’s ports or Gentoo’s portage will install ssmtp for you. If you’ve downloaded the tarball then untar it somewhere and install it in the more or less usual way. This will have to be done as root or with root privilege.

tar -zxvf ssmtp*tar.gz
cd ssmtp*
./configure
make
make install

4.)Configuring ssmtp

The ssmtp program will install either a sample conf file or the actual file in /usr/etc or perhaps /usr/local/etc, depending upon distribution. This file will have to be edited slightly to make it work. Some of the comments in the file can be a bit misleading. I am including an entire file from a FreeBSD installation, with the hope that it will be clearer where you have to make changes. I am typing in ALLCAPS above the lines that you will have to change.

#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#

# The person who gets all mail for userids < 1000
root=postmaster

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.

CHANGE THE LINE BELOW


mailhub=mail

# Example for SMTP port number 2525
# mailhub=mail.your.domain:2525
# Example for SMTP port number 25 (Standard/RFC)
# mailhub=mail.your.domain        
# Example for SSL encrypted connection
# mailhub=mail.your.domain:465

# Where will the mail seem to come from?

THIS LINE WILL HAVE TO BE EDITED


rewriteDomain=

# The full hostname


THE BELOW LINE WILL HAVE TO BE CHANGED


hostname=

# Set this to never rewrite the "From:" line (unless not given) and to
# use that address in the "from line" of the envelope.


THE LINE BELOW SHOULD BE UNCOMMENTED 

#FromLineOverride=YES

# Use SSL/TLS to send secure messages to server.
#UseTLS=YES

# Use SSL/TLS certificate to authenticate against smtp host.
#UseTLSCert=YES

# Use this RSA certificate.
#TLSCert=/usr/local/etc/ssmtp/ssmtp.pem

For our example, we’ll assume that your isp is called isp.com and their smtp server is smtp.isp.com. The local hostname is john.john.com The first line to be changed is the one marked mailhub=mail In our case, with an smtp server called smtp.isp.com it should be changed to read

mailhub=smtp.isp.com

Next, we cover the line that reads rewriteDomain=
Using our example of having an isp called isp.com it should be changed to read

rewriteDomain=isp.com

In other words, the domain of your isp, eg mindspring.com or whatever. Next, the hostname. The line that reads hostname should be changed to the local hostname.

hostname=john.john.com

The last change to be made is in the line that says FromLineOverride=YES. Many people, (judging from google) including myself, found that line a bit confusing. If you don’t uncomment it (by removing the # sign) you may find that all your mail comes from User &. So, uncomment it.

5.) Testing ssmtp

To test ssmtp, try sending an email. You can send one to yourself, and make sure you get it, or elsewhere. You can also look at /var/log/maillog which should show that the mail was sent successfully.

References

man ssmtp

The Quick-N-Dirty Guide to Screen

Screen is a useful application. We’re only going to cover two of its more common uses in this article.

1.) Do you have screen

At a command prompt type

which screen

If you get an answer like /usr/bin/screen or /usr/local/bin/screen go to step three, otherwise go to step two.

2.) Installing screen

See our installation guide for instructions on installing screen in your distribution. It’s a well-known application so almost all distributions have their own version of it.

3.) Using screen

Screen has several uses. My most frequent use of it is when I’m working on something either in X, console or remotely, and may want to change from one to another.

For example, while at home, I log into a server at work. I have something that might take time on the server, but my connection between home and work is problematic. So, I get on through our company’s VPN and log into the server.

Now, I have to copy a very large directory which may take 20 minutes. If my connection gets cut off during that twenty minutes, something may go wrong. However, if I use screen

screen cp SP02 SP02.bak

I can now detach the screen. The default key combination to preface any command to screen is ctrl+A (which will be abbreviated as C-a). So

C-a
d

This will detach the screen. I can now log off. Ten minutes later, I wish to check on its progress so once again I connect and

screen -r

The d and r stand for detach and reattach. If the process is finished, I will get a message that there is no screen to be resumed. Otherwise, it will put me back where I was when I detached the screen.

Another handy use of screen is to make two windows in a console. To do this

C-a
Shift+S

This creates a second window. The cursor is still in the top window

C-a
tab
C-a
c

One tabs to the second window, then does the C-a combination again and c. You will then be able to enter a command. This is far less cumbersome to do than it may seem from reading it.

References
man screen

Checklist for installing Gentoo 1.4 on an i686

    1. Obtain Gentoo and burn it to CD
      QND Gentoo.org
    2. Boot from Gentoo LiveCD, Disc 1
      QND Gentoo.org
    3. Set system data (and time)
      QND Gentoo.org
    4. Create partitions
      QND Gentoo.org
    5. Make filesystems QND
      Gentoo.org
    6. Mount filesystems QND
      Gentoo.org
    7. QND Extract the base system
      Make sure you are in the /mnt/gentoo directory, which is the mountpoint of your root filesystem:

      cd /mnt/gentoo
    8. Now, extract the Stage 3 base system tarball into the current directory:
      tar xvjpf /mnt/cdrom/stages/stage3-i686-*.tar.bz2
    9. Extract the Portage snapshot tarball into the usr/ directory:
      tar xvjf /mnt/cdrom/snapshots/portage-*.tar.bz2 -C usr
    10. Copy the distribution and GRP (Gentoo binary packages) files into your new Portage directory:
      cp -R /mnt/cdrom/distfiles usr/portage/distfiles
      cp -a /mnt/cdrom/packages usr/portage/packages
      

If you would like more information on this step, Gentoo.org

    1. QND Build a chroot jail
    2. Create a chroot jail for your new Gentoo system (yes, believe it or not, you almost have a fully functional system built in the /mnt/gentoo directory):
      chroot /mnt/gentoo /bin/bash
    3. Update your environment (to completely immerse yourself in the Matrix):
      env-update
      source /etc/profile

If you would like more information on this step, Gentoo.org

    1. QND Set your time zone
      Make a symbolic link (AKA symlink AKA soft link) from the zoneinfo file that correctly describes your time zone to /etc/localtime:

      ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

      if you are in North America’s Eastern Standard Time zone. If you are in Ireland, you want to use zoneinfo/Eire; if in Japan, zoneinfo/Japan; if in California, zoneinfo/America/Los_Angeles; if in Bulgaria, zoneinfo/Europe/Sofia; and so on. You should be able to figure it out. 🙂

If you would like more information on this step, Gentoo.org

    1. QND Create your /etc/fstab
      /etc/fstab tells Linux all it needs to know about your filesystems. Open it

      nano -w /etc/fstab

      and edit it (Nano is the GNU clone of Pico, if that helps you; Emacs / Readline style movement generally works; look at the bottom line of Nano for a quick keystroke reference) to look like this:

      # /etc/fstab: static file system information.
      #
      # noatime turns off atimes for increased performance (atimes normally aren't
      # needed; notail increases performance of ReiserFS (at the expense of storage
      # efficiency).  It is safe to drop the noatime options if you want and to 
      # switch between notail and tail freely.
      
      # <fs>           <mount point> <type>   <opts>          <dump/pass>
      
      # NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
      
      /dev/hda1        /boot         ext2        noauto          1 1
      /dev/hda3        /             reiserfs    defaults        0 0
      /dev/hda5        /opt          xfs         defaults        0 0
      /dev/hda6        /tmp          xfs         defaults        0 0
      /dev/hda7        /usr          xfs         defaults        0 0
      /dev/hda8        /var          xfs         defaults        0 0
      /dev/hda9        /home         xfs         defaults        0 0
      
      /dev/hda2        none          swap        sw              0 0
      
      /dev/cdroms/cdrom0 /mnt/cdrom  iso9660     noauto,ro,user  0 0
      
      none             /proc         proc        defaults        0 0

If you have a utility / diagnostics / whatever partition, remember to increment the partition number (and skip the dreaded hda4)!

If you would like more information on this step, Gentoo.org

    1. QND Compile a kernel
    2. This will be your first experience with emerge, which is the program used for manipulating Portage, the Gentoo package system. We will emerge (AKA install) the binary xfs-sources kernel:
      emerge -k xfs-sources

      The -k switch is what tells Portage to use a binary package as opposed to the preferred default source packages. (Though actually, the “binary” kernel package is not much different from the “source” one.)

    3. For some reason, some part of the GRP install seems to create a boot symlink to /boot in the /boot directory, which has the unfortunate result of creating an infinitely deep directory structure. Said foppery will prevent genkernel from installing the kernel. Kill the symlink:
      rm /boot/book
    4. Now, emerge the genkernel script and use it to compile and install your kernel:
      emerge -k genkernel
      genkernel

When genkernel finishes, make sure you have the following files in /boot:

/boot/System.map-version
/boot/kernel-version
      where

version

      is the Linux kernel version (e.g.

2.4.20

      ) plus the Gentoo kernel name (in this case

xfs

      ) and the Gentoo ebuild release (e.g

r3

      ). If these files do not exist, you will have to install the kernel manually:
version=`ls -1 /usr/src/ | grep linux- | awk -F'linux' '{ print $2 }'`
cp /usr/src/linux/System /boot/System.map$version
cp /usr/src/linux/arch/i386/boot/bzImage /boot/kernel$version

If you would like more information on this step, Gentoo.org

    1. QND Install a system logger and cron daemon
      You will install the most standard system logger, sysklogd, and cron daemon, vcron:

      emerge -k sysklogd vcron

      After the packages are installed, add them to the default run-level:

      rc-update add sysklogd default
      rc-update add vcron default

If you would like more information on this step, Gentoo.org

    1. QND Install all other necessary packages
    2. Since you have reiserfs and XFS filesystems, you should install the tools for both:
      emerge -k reiserfsprogs xfsprogs
    3. And if you are installing on a laptop, you will want to install the pcmcia-cs package and add it to the boot run-level:
      emerge -k pcmcia-cs
      rc-update add pcmcia boot

      (this will involve a compile–a binary package is not distributed on the LiveCD).

If you would like more information on this step, Gentoo.org

    1. QND

      14.) Set root’s password

      If you forget to set a password for the root account, you will not be able to login to your box! Do it now:

      passwd root

      Enter a good password, then enter it again for verification.

If you would like more information on this step, Gentoo.org

    1. QND Network setup
      If you are on a LAN, or are connected to the Internet by an Ethernet NIC (e.g. you have a cable or DSL modem), you will want to configure your network settings. If you dial up to the Internet, skip ahead to the next step.
    2. Set your hostname and domain name:
      echo 'hostname.domain.tld' >/etc/hostname
      echo 'domain.tld' >/etc/dnsdomainname
    3. Add at least one nameserver to your /etc/resolve.conf:
      echo 'nameserver 123.456.789.1' >/etc/resolv.conf
      echo 'nameserver 123.456.789.2' >>/etc/resolv.conf

      Please note that in the first step, you are truncating your /etc/resolv.conf, and in the second, you are appending to it (>> versus >)!

    4. Now, configure your primary Network Interface Card (NIC) by entering:
      nano -w /etc/conf.d/net

      Edit the file to look something like this (note that you only need to edit the lines coloured red):

      # /etc/conf.d/net:
      # $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/conf.d/net,v 1.7 2002/11/18 19:39:22 azarah Exp $
      
      # Global config file for net.* rc-scripts
      
      # This is basically the ifconfig argument without the ifconfig $iface
      #
      iface_eth0="192.168.4.209 broadcast 192.168.4.255 netmask 255.255.255.0"
      #iface_eth1="207.170.82.202 broadcast 207.0.255.255 netmask 255.255.0.0"
      
      # For DHCP set iface_eth? to "dhcp"
      # For passing options to dhcpcd use dhcpcd_eth?
      #
      #iface_eth0="dhcp"
      #dhcpcd_eth0="..."
      
      # For adding aliases to a interface
      #
      #alias_eth0="192.168.0.3 192.168.0.4"
      
      # NB:  The next is only used for aliases.
      #
      # To add a custom netmask/broadcast address to created aliases,
      # uncomment and change accordingly.  Leave commented to assign
      # defaults for that interface.
      #
      #broadcast_eth0="192.168.0.255 192.168.0.255"
      #netmask_eth0="255.255.255.0 255.255.255.0"
      
      
      # For setting the default gateway
      #
      gateway="eth0/192.168.4.254"
      

      In the iface_eth0="192.168.4.209 broadcast 192.168.4.255 netmask 255.255.255.0" line, replace 192.168.4.209 with your IP address. Replace 192.168.4.255 with your broadcast address (which is usually just your IP address, except the number after the third dot is 255). If you know that you are not in a class C (or its CIDR equivalent, */24) network, replace 255.255.255.0 with your network mask. If you do not know these settings, consult your ISP, sysadmin, or local networking guru.

If you would like more information on this step, Gentoo.org

    1. QND Setup bootloader
    2. You will need to install a bootloader (in this case, GRUB) in order to boot into Linux:
      emerge -k grub
    3. Now, enter
      nano -w /boot/grub/grub.conf

      to create a GRUB configuration file. Edit it to look like this:

      default 0
      timeout 10
      splashimage=(hd0,0)/grub/splash.xpm.gz
      
      title=Gentoo 1.4 (Linux version)
      root (hd0,0)
      kernel (hd0,0)/kernel-version root=/dev/hda3
      initrd (hd0,0)/initrd-version

      where version is the Linux kernel version (e.g. 2.4.20) plus the Gentoo kernel name (in this case xfs) and the Gentoo ebuild release (e.g r3); i.e. the output of:

      version=`ls -1 /usr/src/ | grep linux- | awk -F'linux' '{ print $2 }'`

If you have a utility / diagnostics / whatever partition, you should change (hd0,0) to (hd0,1)!

The Gentoo instructions for this step (see below) have you enter (hd0,0)/boot instead of just (hd0,0)/. In my experience, GRUB cannot find any files prefixed with /boot. This makes sense in that (hd0,0) refers to the /boot partition, and is probably why the /boot/boot infinite symlink is created. What a kludge!

    1. To invoke the GRUB shell (one of the big reasons why it is the best bootloader, period), enter:
      grub --no-floppy

      You will be presented with a prompt:

          GNU GRUB  version 0.93  (640K lower / 3072K upper memory)
      
       [ Minimal BASH-like line editing is supported.  For the first word, TAB
         lists possible command completions.  Anywhere else TAB lists the possible
         completions of a device/filename. ]
      
      grub>

      To tell GRUB that your boot partition is the first partition (or second, if you have a utility / diagnostics / whatever partition) of the first hard drive, enter:

      root (hd0,0)

If you have a utility / diagnostics / whatever partition, you should change (hd0,0) to (hd0,1)!

GRUB will report:

 Filesystem type is ext2fs, partition type 0x83

To install GRUB onto the Master Boot Record (MBR) of your first hard drive, enter:

setup (hd0)

GRUB will report:

 Checking if "boot/grub/stage1" exists... yes
 Checking if "boot/grub/stage2" exists... yes
 Checking if "boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2
/boot/grub/grub.conf"... succeeded
Done.

To exit GRUB, enter:

quit

If you would like more information on this step, Gentoo.org

    1. QND Install XFree86
      If you are installing Gentoo on a server, you probably do not want to install X. Skip to the next step.QND

Using Portage and GRP, installing XFree86 is a simple as entering:

emerge -k xfree
      Again, the

-k

      flag tells

emerge

      to use binary packages when available.

If you would like more information on this step, Gentoo.org

    1. QND Stage a jail-break and reboot! Viva la revolucion!
      To escape from the chroot jail, enter:

      exit

      or hit Ctrl+d.

Unmount all of your filesystems:

cd /
for i in /mnt/gentoo/*; do
  umount /mnt/gentoo/$i;
done
umount -l /mnt/gentoo
      and reboot:
reboot

Make sure to remove the bootable CD as soon as you are able (i.e. right after the machine resets). If all is well, you will see a slick GRUB menu that will wait 10 seconds, then boot into your new Gentoo Linux system!

If you would like more information on this step, Gentoo.org

    1. QND Install useful software packages
      Login to the system with the root password that you set in Step 14QND.
    2. Insert the Gentoo LiveCD, Disc 2 into your CD-ROM drive and enter:
      cp /mnt/cdrom/packages/All/* usr/portage/packages/All/
      

      which will copy around 450MB worth of binary packages onto your hard drive. Don’t worry, it is only temporary. 🙂

    3. Install a decent editor, vim, and sudo a package that lets you run commands with root privileges without having to be root (so you can avoid the onset of carpal tunnel due to typing su - a thousand times a day):
      emerge -k vim sudo gentoolkit

If you are installing Gentoo on a server, you are done. Create some user accounts and away you go! You should skip the rest of the steps in this guide.

    1. Now, install the window manager of your choice:
      • GNOME
        emerge -k gnome

        Open /etc/rc.conf in a text editor (e.g. nano or vim) and find the line:

        #DISPLAYMANAGER="xdm"

        Add a new line right below it:

        DISPLAYMANAGER="gdm"

        and save and exit the file.

      • GNOME
        emerge -k kde

        Open /etc/rc.conf in a text editor (e.g. nano or vim) and find the line:

        #DISPLAYMANAGER="xdm"

        Add a new line right below it:

        DISPLAYMANAGER="kdm"

        and save and exit the file.

    2. To install the Mozilla web browser, enter:
      emerge -k mozilla
    3. Generate an XFree86 configuration file:
      cd /etc/X11
      XFree86 -configure
      mv ~/XF86Config.new ./XF86Config-4

      Open the newly created /etc/X11/XF86Config-4 file in the editor of your choice (e.g. nano or vim) and find the lines:

      Section "Screen"
              Identifier "Screen0"

      Add a new line right beneath them:

      DefaultDepth    16

      for 16 million colours, or:

      DefaultDepth    24

      for 24 million colours.

Save the file and exit.

  1. To have X start automatically on boot, enter:
    rc-update add xdm default
  2. To start XFree86, using either GNOME or KDE, enter:
    /etc/init.d/xdm start

    If all is well, you should be presented with a graphical login screen. Voila, you have installed Gentoo with XFree86!

The Quick-N-Dirty Guide to Mutt

The aim of these QND guides is to get you up and running quickly. Therefore, there is going to be little explanation of why things work. However, by the end of this article, you will be able to use mutt to send and receive email.

The easiest way to get mail in mutt is to use getmail. So, before starting this guide, take a look at the QND getmail guide. It will only take you a few minutes. Don’t worry, we’ll wait.

(The author greatly prefers getmail to the better known fetchmail. However, for those who must, there is also a QND Fetchmail guide.)

Now to set up mutt. Open up your favorite text editor and make a .muttrc file (note the dot before it).

folder-hook . “my_hdr From: John <john@isp.com>”

The example given is the absolute minimum for a .muttrc. There are often examples, and the references given below go into much greater detail.

Most distributions have a system wide /etc/Muttrc file. It’s always good to take a look at that file to see what is there. (On some distros it’s in /etc/Mutt/muttrc or something similar, but you should be able to find it.

Note that you don’t have to have sendmail, postfix or whatever your MTA is running as a daemon to use mutt. Mutt will call it when necessary.
(Actually, in my experience, postfix can be iffy–sometimes it will work if postfix isn’t started and other times it won’t. I’ve also found that in FreeBSD, this doesn’t seem to be the case. If sendmail isn’t started, the messages will be queued but not sent. However, if you’re using ssmtp as a sendmail replacement, done by typing make replace in /usr/ports/mail/ssmtp, you don’t have to call it before sending mail)

Aliases

The aliases file is comparable to an address book. As this is the QND guide, we’re only covering how to add an address of someone sending you mail.

Open up your .muttrc file and add these two lines

set alias_file=~/.mutt_aliases
source ~/.mutt_aliases

This tells mutt where to look for your aliases. This will serve as an address book. Now we create our .mutt_aliases file.

touch .mutt_aliases

Now, if you receive mail from someone and want to add them to your aliases, while on their email hit the a key. Mutt will begin a dialog. It’s usually safe to accept the defaults save for the last question, which is something like save to /.mutt_aliases?
For that question, change it to ~/.mutt_aliases. If, however, it says save it to /home/john/.mutt_aliases then it’s safe to accept it.

This should enable you to get mutt up and running. Mutt is a very powerful and configurable client and there countless other options. For further reading you can start with a more detailed page of mine and, of course, the mutt manual which should probably be on your machine in /usr/share/doc/mutt[version number]. It’s also available on line here.

The Quick-N-Dirty Guide to Maildrop

Although procmail seems to be more widely used, the maildrop program is preferred by some people. The documentation can be difficult for newcomers, however, its syntax for simple filtering is straightforward.

I want to thank my friend Tillman Hodgson whose pages can be viewed here for helping me understand how simple maildrop’s syntax can be

1.) Do you have maildrop?

At a command prompt type

which maildrop

If you get an answer like /usr/bin/maildrop or /usr/local/bin/maildrop go to step 3, otherwise, go to step 2.

2.) Installing

For help with installing take a look at our QND guide to installing software. If your distribution isn’t covered, then you may have to install from source. Fear not, we have a QND guide for installing from source as well.

3.) Configuring

In our example, we will deal with two mailling lists, list1 and list2.org. We will then create another mailbox to deal with anything having linux in its subject line and then put personal email in its own box and add a line to catch everything else.

Many mailing lists will, if you hit reply when answering a post, simply send the reply to the mailing list. Other lists, (including many technical *nix lists) only reply to the original poster. Some people when replying, change this, sending it only to the group, but many people hit reply, let the To: line go to the original poster and just cc the group. In our example, list1 will be a list where replies automatically go to the entire group and list2.org will be one of those where reply would only reply to the original poster.

Using your favorite text editor, in your home directory, create a file called .mailfilter. Add the following

if (/^To: .*list1/)
        to Mail/IN-list1

if (/^(From|To|cc|bcc): .*list2\.org/)
        to Mail/IN-list2

if (/^Subject: *.linux/)
        to Mail/IN-linux

if (/^To: john/)
        to Mail/IN-personal

DEFAULT="Mail/IN-misc"

As you can see the syntax is rather simple. The first line begins with if (/^ and then the header word such as From: To: Subject: or whatever then /). The next line begins with to then the destination. If you want to handle more than one header keyword, such as To and cc then you put them in their own, second set of parentheses, separated by pipes. Periods (and other special characters) such as the one in .org are escaped with backslashes. One ends the list of rules with the DEFAULT keyword, and in this case puts the path to the default mailbox in double quotes.

Using multiples can also be used with conditions. For example, if my friend John Paul Jones has three email accounts, I could do the following

if (/^From: (.*john|.*jpjones|.*jjones24)/)
        to Mail/IN-jpjones

We take the condition, From: in this case and put the different possibilities in parentheses, again, separated by pipes then end with the usual /).

Although it’s sometimes simpler (and less prone to error) to make a few entries, one can make various combinations. Taking our earlier example, let’s say list2 can also be addressed as 2list. (For example, the FreeBSD-questions list will work as freebsd-questions or questions@freebsd.org)

if (/^(From|To|cc|bcc): (.*list2\.org|.*2list\.org)/)
        to Mail/IN-list2

As you see, the pattern is actually rather simple.

if (/^(thing1|thing2): (otherthing1|otherthing2)/)

(Note that the ^ before the group thing1 means the expression begins with thing1 or thing2–that’s why we use a .* in case From or whatever doesn’t actually begin with the letters thing. Also note the colon after test2 is for header lines like From, To, cc and the like). You could make separate entries for list2 and 2list or do it as shown above, combining it into one expression.

Now that we’ve created our .mailfilter, we only want the owner to have permissions on the file. So do a chmod

chmod 600 .mailfilter 

4.) Testing maildrop

Run your MTA (Mail Transfer Agent). If you use something like getmail run it once with the verbose flag

getmail -v

This will catch some, though not all, syntax errors, as well as other problems (such as allowing group or world permissions on your .mailfilter file). You can start by sending an email to yourself, then run your MTA. If you’ve followed these instructions, then the email should go into your IN-personal mailbox. (Gentoo and some others use .maildir rather than Mail–in that case, of course you would change your .mailfilter accordingly.) With the Maildir format, you may have to add a trailing slash to your rules, such as

if (/^To: john/)
        to .maildir/IN-personal/

If you use SpamAssassin, you can add this rule at the top of your .mailfilter file. (Assuming you wished to move everything that had a score of 4 and above to a spam folder to be checked later)

xfilter "usr/local/bin/spamassassin"
if (/^X-Spam-Level: \*\*\*\*/)
        to Mail/IN-Spam

We use xfilter to run a command in .mailfilter. For example, I sometimes use a despammed.com address. If I do, it puts [despammed] in the subject line. I use xfilter to send a command to sed

xfilter "sed -e '^Subject:.*\[despammed\]/s/\[despammed\]//g'"

Congratulations, you’re done.

References

This QND guide gives a very simple setup. For more complex filtering rules see
man maildrop
man 5 maildropfilter
man5 maildropex
A page of mine about mutt which covers using maildrop with mutt

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!