Useful
- Chkboot - chkboot is a tool to help detect changes to an unencrypted /boot partition.
How to unlock a LUKS encrypted Linux server remotely with Dropbear SSH. Homepage
You need
- An encrypted physical/virtual Linux server with Linux, e.g. Ubuntu 20.04.
- A SSH client on your machine with a generated ssh-keygen. We can create a 4096 bits key by running:
ssh-keygen -b 4096Install the required packets on the server:
sudo apt update && sudo apt dist-upgrade
sudo apt install dropbear initramfs-tools busyboxWe might encounter problems with the install. Fix it with
sudo apt -f installWe get a warning about dropbear: WARNING: Invalid authorized_keys file, remote unlocking of cryptroot via SSH won't work!. This is expected and we ignore this.
Copy the output from your public SSH key
cat ~/.ssh/id_rsa.pub Open the autorized_keys file and paste it into it.
sudo nano /etc/dropbear-initramfs/authorized_keyssudo nano /etc/initramfs-tools/hooks/crypt_unlock.shand paste following content in it:
#!/bin/sh
PREREQ="dropbear"
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. "${CONFDIR}/initramfs.conf"
. /usr/share/initramfs-tools/hook-functions
if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/crypttab" ] ; then
cat > "${DESTDIR}/bin/unlock" << EOF
#!/bin/sh
if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then
kill \`ps | grep cryptroot | grep -v "grep" | awk '{print \$1}'\`
# following line kill the remote shell right after the passphrase has
# been entered.
kill -9 \`ps | grep "\-sh" | grep -v "grep" | awk '{print \$1}'\`
exit 0
fi
exit 1
EOF
chmod 755 "${DESTDIR}/bin/unlock"
mkdir -p "${DESTDIR}/lib/unlock"
cat > "${DESTDIR}/lib/unlock/plymouth" << EOF
#!/bin/sh
[ "\$1" == "--ping" ] && exit 1
/bin/plymouth "\$@"
EOF
chmod 755 "${DESTDIR}/lib/unlock/plymouth"
echo To unlock root-partition run "unlock" >> ${DESTDIR}/etc/motd
fiand make it executable by running
chmod +x /etc/initramfs-tools/hooks/crypt_unlock.shIf you skip this step DHCP is used. Open the file
sudo nano /etc/initramfs-tools/initramfs.conf and add a line which matches your network and network card
#format [host ip]::[gateway ip]:[netmask]:[hostname]:[device]:[autoconf]
#([hostname] can be omitted)
IP=192.168.1.10::192.168.1.1:255.255.255.0::eth0:offOPTIONAL: To change the default SSH port, open the file /etc/dropbear-initramfs/config and add e.g.
DROPBEAR_OPTIONS="-s -I 30 -p 54000"Explanation
-s: disable password logins
-I 30: idle_timeout, disconnect after 30 sec if no traffic is transmitted
-p 54000: listen on port 54000Command
sudo update-initramfs -uThis makes OpenSSH being used after.
sudo update-rc.d dropbear disablerebootssh root@192.168.1.10
ssh root@192.168.1.10 [-i ~/.ssh/id_rsa]unlock # might hang
cryptroot-unlock # or thisExpected output
# cryptroot-unlock
Please unlock disk sda5_crypt:
cryptsetup: sda5_crypt set up successfully
#