Skip to content

Instantly share code, notes, and snippets.

@swamibluedata
Last active August 14, 2020 14:16
Show Gist options
  • Save swamibluedata/2fe039d1c2d68a3443bf6b0fd2f80b92 to your computer and use it in GitHub Desktop.
Save swamibluedata/2fe039d1c2d68a3443bf6b0fd2f80b92 to your computer and use it in GitHub Desktop.
yum install cryptsetup -y
DEVICE_NAME="/dev/xvdb"
PASSWORD="dummy password"
# Create a secret key file
mkdir -p /etc/luks-keys
echo "$PASSWORD" > /etc/luks-keys/secret
cat /etc/luks-keys/secret
echo -n "$PASSWORD" | cryptsetup -q -y -v luksFormat $DEVICE_NAME -
echo -n "$PASSWORD" | cryptsetup -v luksAddKey $DEVICE_NAME /etc/luks-keys/secret
# Open the device for current session
cryptsetup -v luksOpen $DEVICE_NAME encrypted --key-file=/etc/luks-keys/secret
# Setup crypttab to open the file on reboot
UUID=$(cryptsetup luksDump $DEVICE_NAME | grep "UUID" | cut -d":" -f2 | awk '{$1=$1;print}')
echo "encrypted UUID=$UUID /etc/luks-keys/secret luks" >> /etc/crypttab
lsblk
cat /etc/crypttab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment