Thursday, April 24, 2014

Redirect local emails to a remote email account

My previous post is a guide for setting up exim4, an SMTP mail server, to use Gmail as a smarthost. One reason for setting up a mail server is to redirect my local root emails to an Internet email account that I actually monitor. In this way, I won't miss any security alert sent to the local root mailbox.

This post shows you how to set up email redirection. The instructions are similar for various mail servers: exim4, Postfix, or sendmail.

  1. Set up an SMTP server.
  2. Edit /etc/aliases as root.
    mailer-daemon: postmaster
    postmaster: root
    nobody: root
    hostmaster: root
    usenet: root
    news: root
    webmaster: root
    www: root
    ftp: root
    abuse: root
    noc: root
    security: root
    root: peter

    To the left of the colon is the mail alias defined on the local machine. You can send email to a local email alias, say security and the message will be redirected to the account(s) specified to the right of the colon.

    In many default mail server configurations, emails to any alias are forwarded to root. But often root itself is not redirected to a regularly monitored email account.

  3. Redirect root.

    Replace the root: peter line with the line below using your personal email address:

  4. Rebuild alias database.
    $ newaliases
    For sendmail, and Postfix, after you modify the alias file, you need to run the newaliases command to rebuild the mail alias database. For exim4, this step is not required because it relies solely on the alias file and NO database.

To test, send root an email, and verify that the message is delivered to the target remote email account.

$ echo 'Code red'| mail -s 'Hacker Alert' root

Sunday, April 20, 2014

How to setup exim4 on Debian to use Gmail

Why bother configuring an SMTP mail server on your Linux desktop? Especially if you can send and receive all your emails within a web browser using your Gmail account, or with an email client such as Thunderbird.

My reasons are twofold:

  • Some applications running on my desktop require SMTP to be set up.

    My desktop computer is used to stage a WordPress blog. For WordPress to send email, an SMTP server is required.

  • To redirect local root emails.

    Some programs such as sudo send emails to alert the root user of critical security events. For instance, after 3 failed sudo login attempts. But unless these emails are forwarded to an Internet email account that I actually monitor, they are useless.

This post is about configuring exim4, the default mail server on Debian wheezy.

I assume that

  • exim4 is already installed
  • You have a valid Google Gmail account.

Follow the steps below to configure exim4 to send all outbound emails to a remote "smarthost", namely the Google Gmail SMTP server. The smarthost will take care of forwarding the emails to their final destinations.

  1. Reconfigure exim4.

    By default, exim4 is set up for local email delivery only: no emails to remote domains. You can reconfigure the application using the dpkg-reconfigure command or edit directly the configuration file (/etc/exim4/update-exim4.conf.conf).

    $ sudo dpkg-reconfigure exim4-config

  2. Specify exim4 parameters.

    When prompted by dpkg-reconfigure, enter the following values for the respective exim4 parameters.

    Parameters Values
    General type of mail configuration mail sent by smarthost; received via SMTP or fetchmail
    System mail name localhost
    IP addresses to listen on for incoming SMTP connections
    Note: external connections are refused.
    Other destinations for which mail is accepted Leave empty.
    Machines to relay mail for Leave empty.
    IP address or host name of the outgoing smarthost
    Hide local mail name in outgoing mail? No
    Keep number of DNS-queries minimal (Dial-on-Demand)? No
    Delivery method for local mail mbox format in /var/mail/
    Split configuration into small files? No
  3. Provide the Gmail account and password.

    Append the following to /etc/exim4/passwd.client with the proper Gmail account and password:


    This password file contains sensitive account information. You should verify its file permissions and ownership.

    $ ls -al /etc/exim4/passwd.client
    -rw-r----- 1 root Debian-exim 252 Mar 25 17:24 /etc/exim4/passwd.client

    If they are different from the above, use the following commands to set file permissions and ownership.

    $ sudo chown root:Debian-exim /etc/exim4/passwd.client
    $ sudo chmod 640 /etc/exim4/passwd.client
  4. Reload exim4.
    $ sudo update-exim4.conf
    $ invoke-rc.d exim4 restart
    [ ok ] Stopping MTA for restart: exim4_listener.
    [ ok ] Restarting MTA: exim4.
    $ exim4 -qff

    The -qff parameter forces a delivery attempt for every message, whether frozen or not.

To test, send an email to yourself, and check your Inbox:

$ echo test only | mail -s 'Test Subject'

If you open the email, you will see that the From address in the email header is the Gmail account which you configured in /etc/exim4/passwd.client.

If you experience any issue with exim4, check its log file located at /var/log/exim4/mainlog.

Now that an SMTP server is set up, my next post explains how to redirect local root emails to an Internet email account of your choice.

Monday, April 14, 2014

Burn DVD from an iso image

You have backed up a DVD to your hard drive in ISO format. Now, you want to burn a DVD from that image. This post illustrates how, first using the command line, then the GUI.

Command Line

Insert the DVD disc, and issue one of the following commands to burn a disc.

  1. growisofs

    To install growisofs,

    $ sudo apt-get update
    $ sudo apt-get install growisofs  

    To burn DVD,

    $ growisofs  -dvd-compat -Z  /dev/dvd=/home/peter/my.iso 
  2. wodim

    To install wodim,

    $ sudo apt-get update
    $ sudo apt-get install wodim

    Burn a disc like this:

    $ sudo wodim -v dev=/dev/dvd speed=4 -dao  -eject -data /home/peter/my.iso 


The GUI favorites are:

Below are the K3b-specific instructions to burn an ISO image on a DVD.

  1. Run K3b.
  2. Select Burn Image in the Tools menu.
  3. Specify the location of the ISO image file.
  4. Insert a blank DVD disc.

    The Burn Medium field is updated to indicate the detected empty disc.

  5. Click Start.

Thursday, April 10, 2014

Backup DVDs using K3b

My previous post explains how to backup and playback a DVD from an iso image file in the hard way - using the command line. Now, I discuss how to do it with K3b, a GUI tool.

K3b is a tool from the KDE desktop environment. For Debian users, install it as follows:

$ sudo apt-get install k3b


  1. Run K3b.
  2. Click the Copy Medium button, or select Copy Medium in the Tools menu.
  3. Insert your disc into the DVD drive.

    Note that the Source Medium is updated to show the DVD title.

  4. Select Only create image option.

    By default, K3b writes the iso image to disk, copies it to a DVD, and then removes the image on the hard disk. We assume that you only want to backup to the hard disk.

  5. Specify the folder to store iso image.

    Click the Image tab, and select a folder to hold the backup image.

  6. Click Start button.

Mount iso image

Before you can playback from the iso image, you must first mount it. There are GUI tools to mount iso image files. For Debian wheezy, install Furious ISO mount as follows. (For Ubuntu, install gmountiso.)

$ sudo apt-get install furiusisomount

To mount an iso image,

  1. Run Furious ISO mount.
  2. Click Browse to locate the iso image file.
  3. Select Loop.
  4. Click Mount.
  5. Enter the root password to grant permission to mount the iso.

Note the mount point. You need to know the mount point later when you play back the video. By default, the mount point is a sub-directory under your home directory, and is named after the iso image file - /home/peter/NTSurveyDVD5_iso.

Currently, you cannot change the mount point through the GUI. To change it, you need to edit the configuration file ~/.furiusisomount/settings.cfg.

mount_point: /home/peter


There is no shortage of GUI video players. My favorite is VideoLAN, aka vlc.

  1. Run vlc.
  2. Select Open Disc in the Media menu.
  3. To specify the disc device, click Browse to navigate to the mount point.
  4. Click Play.

Sunday, April 6, 2014

Backup and playback DVD from hard drive using command line

This post is about how to backup and playback DVD content on a hard drive using the command line.

  1. Check available space on hard drive.
    $ df -h
    Filesystem               Size  Used Avail Use% Mounted on
    rootfs                   1.4T   41G  1.2T   4% /
    udev                      10M     0   10M   0% /dev
    tmpfs                    1.6G  900K  1.6G   1% /run
    /dev/disk/by-uuid/6c30b  1.4T   41G  1.2T   4% /
    tmpfs                    5.0M     0  5.0M   0% /run/lock
    tmpfs                    9.6G  640K  9.6G   1% /run/shm

    The df command indicates that 1.2 TB is available on my hard drive, which is plenty to hold the 4 GB DVD.

  2. Insert disc into DVD drive.
  3. Backup DVD.

    Both the dd and readom commands write to a single iso file. The dvdbackup command writes out the DVD file structure - the complete VIDEO_TS folder.

    • dd
      $ dd if=/dev/dvd of=~/birthday.iso
      8310528+0 records in
      8310528+0 records out
      4254990336 bytes (4.3 GB) copied, 303.204 s, 14.0 MB/s
    • readom

      According to its man page, "unless you want to risk getting problems, readom should be run as root." Hence, sudo below.

      $ sudo readom dev=/dev/dvd f= ~/birthday.iso 
      Read  speed:  5540 kB/s (CD  31x, DVD  4x).
      Write speed: 22160 kB/s (CD 125x, DVD 16x).
      Capacity: 2077632 Blocks = 4155264 kBytes = 4057 MBytes = 4254 prMB
      Sectorsize: 2048 Bytes
      Copy from SCSI (3,0,0) disk to file '/home/peter/birthday.iso'
      end:   2077632
      addr:  2077632 cnt: 64
      Time total: 277.602sec
      Read 4155264.00 kB at 14968.4 kB/sec.
    • dvdbackup

      The -o parameter specifies the output directory under which the DVD file structure will be copied. This directory does not need to be unique for your DVDs. This is because a title sub-directory will be created under it. For example, you can have a common ~/movies output directory for all your home movies with different titles.

      The -M parameter specifies that you want to "mirror", i.e., backup, the whole DVD.

      The optional -p parameter enables progress reporting during the backup operation.

      $ dvdbackup -p -M -i /dev/dvd -o ~/movies
      libdvdread: Using libdvdcss version 1.2.13 for DVD access
      libdvdread: Attempting to retrieve all CSS keys
      libdvdread: This can take a long time, please be patient
      libdvdread: Get key for /VIDEO_TS/VIDEO_TS.VOB at 0x0000011e
      libdvdread: Elapsed time 0
      libdvdread: Get key for /VIDEO_TS/VTS_01_0.VOB at 0x0000358c
      libdvdread: Elapsed time 0
      libdvdread: Get key for /VIDEO_TS/VTS_01_1.VOB at 0x00003710
      libdvdread: Elapsed time 0
      libdvdread: Found 1 VTS's
      libdvdread: Elapsed time 0
      Copying menu: 100% done (26/26 MiB)
      Copying menu: 100% done (1/1 MiB)
      Copying Title, part 1/4: 100% done (1024/1024 MiB)
      Copying Title, part 2/4: 100% done (1024/1024 MiB)
      Copying Title, part 3/4: 100% done (1024/1024 MiB)
      Copying Title, part 4/4: 100% done (958/958 MiB)
  4. Playback video.

    My favorite video player is VideoLAN, aka vlc. It can open an iso file as well as a title directory.

    To play back a DVD backed up using dvdbackup:

    $ vlc --fullscreen  ~/movies/2014birthday

    Note that 2014birthday is the title directory created under the ~/movies directory.

    To play back a DVD backed up using dd or readom, you need to first mount the iso file:

    $ sudo mkdir /mnt/iso
    $ sudo mount -t iso9660 -o ro,loop ~/birthday.iso /mnt/iso
    $ vlc --fullscreen  /mnt/iso

My next article discusses the same topic but introduces GUI tools.

Tuesday, April 1, 2014

Increase font size of virtual terminals

My earlier post shows how to change, on the fly, the font size of X terminal emulators. Besides terminal emulators, Linux provides six virtual terminals which you can bring up from X Window by pressing Control+Alt+F1 to Control+Alt+F6 keys respectively. This post explains how to adjust the font size of virtual terminals for Debian, Ubuntu, and their derivatives.

Replace console-tools with kbd

By default, Debian installs the console package console-tools instead of kbd. With console-tools, the console font is limited to 8 pixels wide. If your concern is eye fatigue, you do want a wider font. Installing the kbd package automatically removes console-tools.

$ sudo apt-get install kbd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  console-tools kbd-compat
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 2 to remove and 3 not upgraded.

View live

A bonus for installing kbd is the setfont utility that is included in the package. With setfont, you can temporarily change the font of a virtual terminal, and view it live to decide if you want to configure it permanently.

You can't arbitrarily pick a font for a virtual terminal. The available fonts are stored in the directory /usr/share/consolefonts.

The name of a font file - Uni2-Terminus28x14.psf.gz - tells you 3 key pieces of information:

  • Codeset.

    For English-speaking users, select the codeset Uni2 or Lat15.

  • Font face.

    Popular choices are Terminus and Fixed.

  • Font size.

    The font size is specified by 2 numbers in pixels represented as HEIGHT x WIDTH. If the width is 8 pixels, then only the height is specified. For comparison purposes, the default console font size is 16 (that is, 16 x 8).

To view a font live, press Control+Alt+F1 keys to bring up virtual terminal #1, and then execute the setfont command.

$ setfont /usr/share/consolefonts/Uni2-Terminus28x14.psf.gz

Configure permanently new font and font size

You can directly edit the console configuration file (/etc/default/console-setup). But, it is much easier to run the reconfigure program as below.

  1. Run dpkg-reconfigure.
    $ sudo dpkg-reconfigure console-setup
    [sudo] password for peter: 
  2. Select UTF-8.
  3. Select Combined - Latin; savic Cyrillic; Greek.

    This corresponds to the Uni2 codeset.

  4. Select Terminus.
  5. Select the desired font size.
  6. Run setupcon in virtual terminals.

    If you now switch to a virtual terminal, you will still see the old font size until you run the following command from the virtual terminal.

    $ setupcon