Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
syno:dsm7rescue [2026/09/02 15:53] Bernard Condrausyno:dsm7rescue [2026/09/02 22:35] (current) – [Prepare DSM to get access through SSH with password login enabled] Bernard Condrau
Line 2: Line 2:
  
 ===== Prepare DSM to get access through SSH with password login enabled ===== ===== Prepare DSM to get access through SSH with password login enabled =====
-  Prepare 2 files within top level directory ''/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''.  +  Prepare 2 files within top level directory ''/volume2''. The name is optional but must be a directory outside of the encrypted ''/volume1'' and also outside of any operating system or Synology created 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''
-  * File 1:<code>#!/bin/sh+  - I wrote 2 shell files which run in ''/bin/sh'' or ''/bin/bash''. They regularly check existence of ''/volume1/homes'', and if the script detects the homes directory is not accessible it restarts the SSH daemon with password login enabled. To further safeguard it against misuse my DSM first contacts an external (cloud) server and requests the 2-factor-login key for my user account, which I activated with 2FA served through google authenticator. Without the 6 digit login key served from my cloud server, which serves it only if the request originates from my own fixed IP NAS, password login is not enabled. 
 +  - There are 3 files required to make this concept work, the first 2 which are ''enablepwd'' and ''queryotp'' reside on my NAS under ''/volume2/rescue/batch/'', the third one ''synology.php'' serves the OTP and resides on my cloud server. 
 +  - Enable password login with ''enablepwd'':<code>#!/bin/sh
 # #
 # This script checks availability of a fully encrypted volume1 and enables password authentication for SSH in case the volume is locked # This script checks availability of a fully encrypted volume1 and enables password authentication for SSH in case the volume is locked
Line 51: Line 53:
 exit 1 exit 1
 </code> </code>
-  * File 2:<code>#!/bin/sh+  - Query OTP with ''queryotp'':<code>#!/bin/sh
 # #
 # Query OTP # Query OTP
Line 58: Line 60:
 # 2026-08-31: initial # 2026-08-31: initial
 # #
-OTPQ="https://sec.condrau.com/html/synology.php?share=merkur-otp&auth=myaazrhHCTcNSekHcBp7qNEj"+OTPQ="https://your.cloud.tld/html/synology.php?share=merkur-otp&auth=your-safe-authentication-password-which-should-have-24-or-more-characters"
 AUTH=0; AUTH=0;
 CODE="`wget -qO - $OTPQ`" CODE="`wget -qO - $OTPQ`"
Line 77: Line 79:
 exit 1 exit 1
 </code> </code>
 +  - Serving the OTP through wget to ''synology.php'':<code><?php
 +/*
 + * php to deliver encryption key to remote NAS
 + *
 + * (c) 2026, Bernard Condrau
 + *
 + */
 +
 +// Build an array of trusted IP addresses...
 +$trusted=array('nas.server1.ip.addr', 'nas.server2.ip.addr');
 +
 +// check if request is made from valid ip address
 +if (in_array($_SERVER['REMOTE_ADDR'], $trusted) && isset($_SERVER['QUERY_STRING'])) {
 + $password = array(
 + 'merkur-otp' => ['your-safe-authentication-password-which-should-have-24-or-more-characters',
 + shell_exec('/home/user/html/merkur-otp.sh') // generate OTP
 + ],
 + );
 + // get the share name from the request
 + $share = $_GET['share'];
 + if (isset($password[$share]) && ($password[$share][0] == $_GET['auth'])) {
 + echo $password[$share][1]; // echo the password, this will be grabbed by wget
 + exit(0);
 + }
 +}
 +echo '';
 +?></code>
 +  - Compute the OTP in ''merkur-otp.sh'', this code could also be integrated in file ''synology.php'':<code>#!/bin/bash
 +source /home/bco/html/pyotp-env/bin/activate
 +python3 /home/bco/html/pyotp-env/merkur-otp.py
 +deactivate
 +exit 0</code>
 +  - Set up a task in //Task Scheduler// of your DSM. Choose as task ''bash /volume2/rescue/batch/enablepwd'', let it run as root every 15 minutes or in an interval which suits you. Whenever the script detects ''/volume1/homes/'' as non-accessible it will query the cloud server for the OTP and if the OTP matches synology's internal computation of the OTP it will restart the sshd daemon with password login enabled, allowing you to login even if the encrypted volume is not accessible. You can then proceed with one of the unlock actions described below.
  
 ===== How to gain access to encrypted volumes when the KMIP Server was unavailable during DSM boot ===== ===== How to gain access to encrypted volumes when the KMIP Server was unavailable during DSM boot =====