This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| syno:dsm7rescue [2026/09/02 15:46] – Bernard Condrau | syno:dsm7rescue [2026/09/02 22:35] (current) – [Prepare DSM to get access through SSH with password login enabled] Bernard Condrau | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Rescue an encrypted volume ====== | ====== Rescue an encrypted volume ====== | ||
| + | |||
| + | ===== Prepare DSM to get access through SSH with password login enabled ===== | ||
| + | - Prepare 2 files within top level directory ''/ | ||
| + | - I wrote 2 shell files which run in ''/ | ||
| + | - There are 3 files required to make this concept work, the first 2 which are '' | ||
| + | - Enable password login with '' | ||
| + | # | ||
| + | # 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 ' | ||
| + | # Must be run as root, place it in the task scheduler with regular execution | ||
| + | # (c) Bernard Condrau | ||
| + | # 2026-08-31: initial | ||
| + | # | ||
| + | VOLUME="/ | ||
| + | SSHD_CONFIG="/ | ||
| + | PWD_AUTH_STR=" | ||
| + | BASE_PATH=$( cd -- "$( dirname -- " | ||
| + | QUERY_OTP=$BASE_PATH"/ | ||
| + | LOG_FILE=$BASE_PATH"/ | ||
| + | # | ||
| + | # check whether password authentication is enabled | ||
| + | head -n 1 $SSHD_CONFIG | grep -q " | ||
| + | echo " | ||
| + | # | ||
| + | # check whether homes exists (e.g. volume1 is decrypted) | ||
| + | if [ -d " | ||
| + | echo "homes exists." | ||
| + | if [[ -n " | ||
| + | # disable password authentication | ||
| + | $QUERY_OTP | ||
| + | if [ $? -eq 0 ]; then | ||
| + | sed -i " | ||
| + | synosystemctl restart sshd | ||
| + | echo " | ||
| + | exit 0 | ||
| + | fi | ||
| + | fi | ||
| + | else | ||
| + | echo "homes does not exist." | ||
| + | if [[ -z " | ||
| + | # enable password authentication | ||
| + | $QUERY_OTP | ||
| + | if [ $? -eq 0 ]; then | ||
| + | sed -i "1i $PWD_AUTH_STR" | ||
| + | synosystemctl restart sshd | ||
| + | echo " | ||
| + | exit 0 | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | exit 1 | ||
| + | </ | ||
| + | - Query OTP with '' | ||
| + | # | ||
| + | # Query OTP | ||
| + | # must be run as root | ||
| + | # (c) Bernard Condrau | ||
| + | # 2026-08-31: initial | ||
| + | # | ||
| + | OTPQ=" | ||
| + | AUTH=0; | ||
| + | CODE=" | ||
| + | SYNO=$(sudo synootp username=bco code=$CODE) | ||
| + | if [[ $SYNO == 'auth ok' ]]; then | ||
| + | echo ' | ||
| + | exit 0 | ||
| + | else | ||
| + | sleep 35 | ||
| + | CODE=" | ||
| + | SYNO=$(sudo synootp username=bco code=$CODE) | ||
| + | if [[ $SYNO == 'auth ok' ]]; then | ||
| + | echo ' | ||
| + | exit 0 | ||
| + | fi | ||
| + | fi | ||
| + | echo 'not authenticated' | ||
| + | exit 1 | ||
| + | </ | ||
| + | - Serving the OTP through wget to '' | ||
| + | /* | ||
| + | * php to deliver encryption key to remote NAS | ||
| + | * | ||
| + | * (c) 2026, Bernard Condrau | ||
| + | * | ||
| + | */ | ||
| + | |||
| + | // Build an array of trusted IP addresses... | ||
| + | $trusted=array(' | ||
| + | |||
| + | // check if request is made from valid ip address | ||
| + | if (in_array($_SERVER[' | ||
| + | $password = array( | ||
| + | ' | ||
| + | shell_exec('/ | ||
| + | ], | ||
| + | ); | ||
| + | // get the share name from the request | ||
| + | $share = $_GET[' | ||
| + | if (isset($password[$share]) && ($password[$share][0] == $_GET[' | ||
| + | echo $password[$share][1]; | ||
| + | exit(0); | ||
| + | } | ||
| + | } | ||
| + | echo ''; | ||
| + | ?></ | ||
| + | - Compute the OTP in '' | ||
| + | source / | ||
| + | python3 / | ||
| + | deactivate | ||
| + | exit 0</ | ||
| + | - Set up a task in //Task Scheduler// of your DSM. Choose as task '' | ||
| + | |||
| + | ===== How to gain access to encrypted volumes when the KMIP Server was unavailable during DSM boot ===== | ||
| + | * If you can re-establish connection to the KMIP Server you can do the following: | ||
| + | - SSH into DSM | ||
| + | - if you want to continue using the KMIP Server:< | ||
| + | shutdown -r now</ | ||
| + | - if you do not want to continue using the KMIP Server:< | ||
| + | - Log into DSM and open Storage Manager. You can now access DSM through it's web interface, but you cannot access your files. | ||
| + | - Reset the Encryption Key Vault in the //Global Settings// of the **Storage Manager** using the recovery key to disconnect your NAS from the KMIP Server. | ||
| + | - If your locked volume is not the same volume where your user home directories reside you can go to the **Storage Manager** and select the locked volume, then click the ellipsis (...) icon, and select //Unlock//. Upload your '' | ||
| + | |||
| + | ===== Recover an encrypted volume using an SSH shell ===== | ||
| + | * If you can not re-establish connection to the KMIP Server you can do the following: | ||
| + | - Identify the Target Device Node | ||
| + | * Synology layers its storage using Linux mdadm (RAID) and Logical Volume Management (LVM). You need to find the logical volume path:< | ||
| + | * Look for your volume path, e.g. '' | ||
| + | - Unlock the LUKS Container | ||
| + | * Depending on what credentials you have, choose Option A or Option B | ||
| + | * Option A: Using the Passphrase. Pass the LVM path to cryptsetup to open it. This will prompt you for the password:< | ||
| + | * Option B: Using the Recovery Key (.rkey file). If you have the '' | ||
| + | * Note: mapped_volume is just a temporary virtual name you assign for the next step. | ||
| + | - Mount the Filesystem | ||
| + | * Synology volumes typically use the Btrfs or ext4 file systems. Create a temporary folder and mount the newly decrypted mapping:< | ||
| + | mount / | ||
| + | - Access and Rescue Your Data | ||
| + | * Your data is now fully unencrypted and accessible in plain text at ''/ | ||
| + | |||
| + | ===== How to Regenerate and Download a Recovery Key ===== | ||
| + | - Open **Storage Manager** in Synology DSM | ||
| + | - Go to **Storage** and click on your encrypted volume | ||
| + | - Click the // | ||
| + | - Locate the **Recovery Key** section | ||
| + | - Click // | ||
| + | - Enter your Vault Password when prompted to authorize the action | ||
| + | - The new recovery key file ('' | ||
| + | |||