ใช้ guideline จาก
https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotely-in-linux
สำหรับ config ให้เครื่อง “server” ที่ root disk ถูก encrypted เอาไว้ สามารถ decrypt และ boot ขึ้นมาได้โดยไม่ต้องไปใส่ passphrase ที่ console ของเครื่อง
วิธีการก็คือตอนที่เครื่อง boot ขึ้นมาโดยใช้ initramfs นั้น เดิมทีใน initramfs เฉพาะโปรแกรมที่จำเป็นสำหรับการ decrypt ตัว root disk และ load ส่วนของที่เหลือใน stage ถัดไป ก็ให้เพิ่ม ssh daemon เข้าไปด้วย เพื่อให้สามารถเข้าไป decrypt root disk โดยการ secure shell connect เข้าไปได้
ใช้งานได้สักพัก ก็รู้สึกขี้เกียจที่จะต้องไปกดปุ่มเปิดเครื่อง และป้อน passphrase เอง ก็เลยตัดสินใจ wake-on-lan สำหรับการ boot เครื่อง และ shell script ง่ายๆ สำหรับการ ป้อน passphrase ประมาณนี้
#!/bin/sh
SVR_MAC="00:11:22:33:44:55" # MAC Address of the Server
SVR_IP="192.168.0.9" # IP Address of the Server
DEV="eth0" # Device name of Client for sending etherwake
DATE1=$(date)
D1=$(date +%s)
sudo etherwake -i ${DEV} ${SVR_MAC}
COUNT=0
while true; do
fping -q ${SVR_IP}
[ $? = 0 ] && break
COUNT=$(expr ${COUNT} + 1)
if [ ${COUNT} -gt 60 ]; then
echo "Stage1: Wait too long..."
exit
fi
printf "."
done
printf "\n$(date '+%Y-%m-%d %H:%M:%S') ${SVR_IP} is ready.\n"
echo -n "${PASS}" | ssh root@${SVR_IP} cryptroot-unlock 2> /dev/null 1> /dev/null
COUNT=0
while true; do
echo "pwd" | ssh ${SVR_IP} 2> /dev/null 1> /dev/null
[ $? = 0 ] && break
COUNT=$(expr ${COUNT} + 1)
if [ ${COUNT} -gt 60 ]; then
echo "Stage2: Wait too long..."
exit
fi
printf "+"
done
printf "\n$(date '+%Y-%m-%d %H:%M:%S') ${SVR_IP} ssh is ready.\n"
DATE2=$(date)
D2=$(date +%s)
ACTIVATE_TIME=$(expr ${D2} - ${D1})
echo "Started At : ${DATE1}"
echo "Ended At : ${DATE2}"
echo "Activate Time : ${ACTIVATE_TIME} secs"
cj@olivaw:~$ bin/wakeup-giskard.sh
……………..
2024-08-12 13:11:02 192.168.188.50 is ready.
++++++++++++++++++
2024-08-12 13:12:14 192.168.188.50 ssh is ready.
Started At : Mon Aug 12 01:09:52 PM +07 2024
Ended At : Mon Aug 12 01:12:14 PM +07 2024
Activate Time : 142 secs