SendXMPP mail forward on Debian Jessie

To have a more comfortable way of receiving messages by my servers, I wanted all my root E-Mails to be forwarded to my mobile via XMPP. I only have a limited exim4 on my machine running, configured for local mail delivery only.

So what is the solution

1. Install sendxmpp

apt-get install sendxmpp

2. Create config file as “/etc/sendxmpp.conf”

@

as an example:

sendinguser@jabber.mydomain.com supersecretpassword! mydomain.com

3. Set the right permissions and owner

chmod 600 /etc/sendxmpp.conf
chown Debian-exim:Debian-exim /etc/sendxmpp.conf

4. Create a script to call sendxmpp as “/usr/sbin/mail2xmpp”. It might be that you could put this completely into the alias, however I decided to use the script.
Exchange with your receiving ID. “-t” enables the TLS connection for sending the message.

#!/bin/bash 
echo "$(cat)" | sendxmpp -t  -f /etc/sendxmpp.conf

5. Make script executable

chmod 755 /usr/sbin/mail2xmpp

6. Create the alias for the user, which E-Mails you want to forward in “/etc/aliases”

root: , |/usr/sbin/mail2xmpp

7. To activate pipe forwarding we have to create “/etc/exim4/exim4.conf.localmacros”

SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe

8. Run newaliases and restart exim4 for config to take effect

newaliases
service exim4 restart

Now you should be able to test if it works, by simply sending a local test E-Mail to user “root”.

Advertisements

Unlock LUKS via SSH in Debian

As already described in my previous post (Headless Debian install via SSH), I am dealing with a headless system. As I am encrypting my system and drives with LUKS, I need a way to enter the password in case of a reboot.

So what is the solution

1. Install Dropbear on the server

apt-get install dropbear

2. Configure initramfs network usage; edit “/etc/initramfs-tools/initramfs.conf”. You probably have to add the lines for dropbear and update the device string.

This configuration is using DHCP to obtain an IP, if you have a static configuration, use:
IP=<SERVER-IP>::<STANDARD-GATEWAY>:<SUBNETMASK>:<HOSTNAME>:eth0:off

# 
# DROPBEAR: [ y | n ]
# 
# Use dropbear if available.
# 

DROPBEAR=y
DEVICE=eth0
IP=:::::eth0:dhcp

3. Delete the standard private and public keys on the server

rm /etc/initramfs-tools/root/.ssh/id_rsa
rm /etc/initramfs-tools/root/.ssh/id_rsa.pub

4. Create your own key pair (we assume you use id_rsa as a name) on your client machine and upload it to the server.

ssh-keygen
scp ~/.ssh/id_rsa.pub myuser@debian_headless:id_rsa.pub

5. Then log in to the server and add the key to authorized_key file an remove the public key on the server.

ssh myuser@debian_headless
sudo sh -c "cat id_rsa.pub >> /etc/initramfs-tools/root/.ssh/authorized_keys"
rm id_rsa.pub

6. Now we need to update initramfs and grub

update-initramfs -u -k all
update-grub2

7. On some configurations the network won’t get reconfigured on runtime values, hence we need to trigger an update. Edit “/etc/network/interfaces” and add as first line of the primary interface:

pre-up ip addr flush dev eth0

8. Restart server and log in from your client

ssh -i ~/.ssh/id_rsa root@<server-ip>

9. Set the password to unlock

echo -n "<LUKS encryption password>" > /lib/cryptsetup/passfifo
exit

The server should now boot normally and regular SSH should come up.

Optional: You can also create a little script for the passphrase in “/etc/initramfs-tools/hooks/unlock”

#!/bin/sh
PREREQ=""
 prereqs()
 {
 echo "$PREREQ"
 }
 case $1 in
 prereqs)
 prereqs
 exit 0
 ;;
 esac
. /usr/share/initramfs-tools/hook-functions
cat > "${DESTDIR}/root/unlock" << EOF #!/bin/sh /lib/cryptsetup/askpass 'passphrase: ' > /lib/cryptsetup/passfifo
 EOF
chmod u+x "${DESTDIR}/root/unlock"
exit 0

Do not forget to make it executable

chmod +x /etc/initramfs-tools/hooks/unlock

And update initramfs

update-initramfs -u -k all
update-grub2

Headless Debian install via SSH

Having build a NAS system recently, I realized I do not have any monitors or keyboards at home anymore. Hence installing Debian will be hard.

I looked around and the solution would be a headless install via ssh.

This post is based on some work from S.G. Vulcan’s post Installing Debian using only SSH

His post was a good start, but I only could make it work for a Debian Jessie netinstall image after some changes.

So what is the solution

1. Download the latest netinstall image from Debian, I used “debian-8.3.0-amd64-netinst.iso”

2. Mount the ISO to a folder

mkdir isoorig
mount -o loop -t iso9660 debian-8.3.0-amd64-netinst.iso isoorig

3. Copy to new folder called isonew

mkdir isonew rsync -a -Hexclude=TRANS.TBL isoorig/ isonew

4. Change the menu to load SSH on boot by default, edit isonew/isolinux/txt.cfg

remove:

“menu default” from “label install”

add:
Here I changed the vga parameters and adapted the kernel parameters to arm to match my original ISO.

label netinstall
menu label ^Install Over SSH 
menu default
kernel /install.arm/vmlinuz
append auto=true vga=788 file=/cdrom/preseed.cfg initrd=/install.arm/initrd.gz locale=en_US console-keymaps-at/keymap=us

change:

“default install” to “default netinstall”

5. Create isonew/preseed.cfg file

I adapted the locale and keyboard settings for Germany and added the selection of the keyboard-configuration. This would otherwise be an open question during the install and we won’t reach the SSH startup.
Also I added a check for non-free firmware, which popped up on one of my machines which had wireless.

#### Contents of the preconfiguration file
### Localization
# Locale sets language and country.
d-i debian-installer/locale select de_DE
# Keyboard selection.
d-i console-keymaps-at/keymap select de
d-i keyboard-configuration/xkb-keymap select de
### Network configuration
# netcfg will choose an interface that has link if possible. This makes it
# skip displaying a list if there is more than one interface.
d-i netcfg/choose_interface select auto
# Any hostname and domain names assigned from dhcp take precedence over
# values set here. However, setting the values still prevents the questions
# from being shown, even if values come from dhcp.
d-i netcfg/get_hostname string newdebian
d-i netcfg/get_domain string local
# If non-free firmware is needed for the network or other hardware, you can
# configure the installer to always try to load it, without prompting. Or
# change to false to disable asking.
d-i hw-detect/load_firmware boolean true
# The wacky dhcp hostname that some ISPs use as a password of sorts.
#d-i netcfg/dhcp_hostname string radish
d-i preseed/early_command string anna-install network-console
# Setup ssh password
d-i network-console/password password install
d-i network-console/password-again password install

6. Recreate md5sum.txt
md5sum.txt is read only, so you need to change this. Also I had better luck with creating the md5sum.txt with the changed command below.

chmod 666 md5sum.txt
find -follow -type f -exec md5sum {} \; > md5sum.txt
chmod 444 md5sum.txt

7. Create ISO file to burn

xorriso -as mkisofs -D -r -J -joliet-long -l -V "Debian headless" -b isolinux/isolinux.bin -c isolinux/boot.cat -iso-level 3 -no-emul-boot -partition_offset 16 -boot-load-size 4 -boot-info-table -isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin -o ../debian-8.3.0-amd64-netinst-headless.iso ../isonew

xorriso is creating a correct partition table, which is for some reason not done with mkisofs only. If you do not have it installed use “apt-get install xorriso”.
The original command would work in VMs, maybe even on a cd-rom, however not for USB sticks.

8. Use the ISO

The ISO can be burned to an USB stick and used to boot. It will automatically configure the network with DHCP (yes, you need to have a way to find the IP, e.g. on your router) and start SSH.

The user for the ssh connection is “installer” the password is “install”

Duplicity backup to Amazon S3 on Debian

I am using duplicity with duply to do PGP encrypted backups to Amazon S3. As there are enough guides around for the basic setup (i used Backup unter Linux mit duply), I won’t go into details of that.
However if you are planning to use the new EU (Frankfurt) location called eu-central-1 you will run into problems as this location only supports the V4 authentication.

You might encounter the following error when using duply (even if the config worked on other locations before)

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

So what is the solution

This is a bit tricky, as the Debian packages are not up to date and you need to mix backports and unstable versions.

To solve this you will need to upgrade your duplicity and boto framework as following:

Package duplicity needs version > 0.7.02-1
This version is available within the backport branch of Debian. I used package pinning to get this package. You can easily find articles for this via Google, I found this one helpful.
Be careful to understand pinning, as you might confuse APT with a wrong configuration. You should always use sudo apt-cache policy [packagename] and the -s parameter on upgrades first to check what will happen.
Currently I am using duplicity 0.7.06-1~bpo8+1.

Package python-boto needs version >= 2.36.0
Previously this was only available via PyPi, however a newer version is now available in the unstable branch. Hence again you can install this via pinning.
Currently I am using python-boto 2.40.0-1

Package duply did not need additional changes, I am using version 1.9.1-1 out of the regular stable branch