This is an old revision of the document!
/volume2. The name is optional but must be a new directory so that these 2 files are kept intact when DSM get's updated, they must be treated as user files. In my setup Synology created /volume2 automatically when I created the fully encrypted /volume1. #!/bin/sh
#
# This script checks availability of a fully encrypted volume1 and enables password authentication for SSH in case the volume is locked
# After restarting the SSH daemon it allows to login even though the homes directory is not accessible
# It requires script 'queryotp' to provide a valid google authenticator code without which it will do nothing
# Must be run as root, place it in the task scheduler with regular execution
# (c) Bernard Condrau
# 2026-08-31: initial
#
VOLUME="/volume1/homes"
SSHD_CONFIG="/etc/ssh/sshd_config"
PWD_AUTH_STR="PasswordAuthentication yes"
BASE_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
QUERY_OTP=$BASE_PATH"/queryotp"
LOG_FILE=$BASE_PATH"/../logs/enablepwd.log"
#
# check whether password authentication is enabled
head -n 1 $SSHD_CONFIG | grep -q "$PWD_AUTH_STR" && ENABLED="yes" || ENABLED=""
echo "$(date +'%Y-%m-%d %H.%M'): enablepwd task run" | tee -a $LOG_FILE
#
# check whether homes exists (e.g. volume1 is decrypted)
if [ -d "$VOLUME" ]; then
echo "homes exists."
if [[ -n "$ENABLED" ]]; then
# disable password authentication
$QUERY_OTP
if [ $? -eq 0 ]; then
sed -i "1d" $SSHD_CONFIG
synosystemctl restart sshd
echo "$(date +'%Y-%m-%d %H.%M'): \"$PWD_AUTH_STR\" removed" | tee -a $LOG_FILE
exit 0
fi
fi
else
echo "homes does not exist."
if [[ -z "$ENABLED" ]]; then
# enable password authentication
$QUERY_OTP
if [ $? -eq 0 ]; then
sed -i "1i $PWD_AUTH_STR" $SSHD_CONFIG
synosystemctl restart sshd
echo "$(date +'%Y-%m-%d %H.%M'): \"$PWD_AUTH_STR\" added" | tee -a $LOG_FILE
exit 0
fi
fi
fi
exit 1
#!/bin/sh # # Query OTP # must be run as root # (c) Bernard Condrau # 2026-08-31: initial # OTPQ="https://sec.condrau.com/html/synology.php?share=merkur-otp&auth=myaazrhHCTcNSekHcBp7qNEj" AUTH=0; CODE="`wget -qO - $OTPQ`" SYNO=$(sudo synootp username=bco code=$CODE) if [[ $SYNO == 'auth ok' ]]; then echo 'authenticated' exit 0 else sleep 35 CODE="`wget -qO - $OTPQ`" SYNO=$(sudo synootp username=bco code=$CODE) if [[ $SYNO == 'auth ok' ]]; then echo 'authenticated' exit 0 fi fi echo 'not authenticated' exit 1
reboot shutdown -r now
sudo /usr/syno/sbin/synoencvolume --auto-unlock-get-keys
.rkey recovery file. The system will prompt you to enter a new vault password to recreate and repair the local key vault.sudo lvdisplay
LV Path /dev/vg1/volume_1sudo cryptsetup luksOpen /dev/vg1/volume_1 mapped_volume
.rkey file saved on a USB drive or transferred via SSH to /tmp/volume1.rkey, use:sudo cryptsetup luksOpen /dev/vg1/volume_1 mapped_volume --key-file /tmp/volume1.rkey
sudo mkdir -p /mnt/recovery mount /dev/mapper/mapped_volume /mnt/recovery
/mnt/recovery. You can use command-line tools like cp, rsync, or tar to copy your files off to an external drive or another server..rkey) will download automatically to your computer's default download folder