Created
January 1, 2024 23:25
-
-
Save pfichtner/2e2611009e5dcd26a182f34f9055564d to your computer and use it in GitHub Desktop.
Automatically unlock a remote luks drive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # client: ssh-keygen -f $keyname -t rsa -b 4096 -o -a 100 | |
| # server: apt install dropbear-initramfs | |
| # server: add generated public key of keypair to /etc/dropbear/initramfs/authorized_keys | |
| # server: update-initramfs -u | |
| REMOTE_USER="root" | |
| REMOTE_HOST="192.168.x.xxx" | |
| IDENTITY_FILE="~/.ssh/lukstest" | |
| # can be generated via ssh-keyscan -H "$REMOTE_HOST" >"$KNOWNHOSTS_FILE" | |
| KNOWNHOSTS_FILE="/path/to/known_hosts" | |
| SCRIPT_PATH="cryptroot-unlock" | |
| echo -n "Enter LUKS passphrase to send: " | |
| read -s PASSPHRASE | |
| echo | |
| while true; do | |
| echo -n "$PASSPHRASE" | ssh -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$KNOWNHOSTS_FILE" -i "$IDENTITY_FILE" -T -o "SendEnv=TERM" "$REMOTE_USER@$REMOTE_HOST" "$SCRIPT_PATH" | |
| if [ $? -eq 0 ]; then | |
| echo "Successfully unlocked" | |
| fi | |
| sleep 5 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment