Skip to content

Instantly share code, notes, and snippets.

@michaelmrose
Last active March 24, 2025 20:04
Show Gist options
  • Save michaelmrose/3d6ba4d9e01fd49bfca73cf7b7eaf8d2 to your computer and use it in GitHub Desktop.
Save michaelmrose/3d6ba4d9e01fd49bfca73cf7b7eaf8d2 to your computer and use it in GitHub Desktop.

Revisions

  1. michaelmrose revised this gist Mar 24, 2025. 2 changed files with 7 additions and 3 deletions.
    4 changes: 3 additions & 1 deletion system-auth
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    auth optional pam_exec.so expose_authtok /usr/local/bin/zfs-unlock-home.sh
    AFTER pam_unix.so

    auth optional pam_exec.so expose_authtok /usr/local/bin/zfs-unlock-home.sh ifok

    remainder redacted
    6 changes: 4 additions & 2 deletions zfs-unlock-home.sh
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,11 @@

    # Adjust to match your dataset
    ZFS_DATASET="trident/home/michael"
    PASS=`cat -`

    # Only try if dataset is encrypted and not mounted
    if ! zfs get -H -o value mounted "$ZFS_DATASET" | grep -q "yes"; then
    echo "$PAM_AUTHTOK" | zfs load-key "$ZFS_DATASET"
    echo attempting to load key and mount
    echo "$PASS" | zfs load-key "$ZFS_DATASET"
    zfs mount "$ZFS_DATASET"
    fi
    fi
  2. michaelmrose created this gist Mar 24, 2025.
    3 changes: 3 additions & 0 deletions system-auth
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    auth optional pam_exec.so expose_authtok /usr/local/bin/zfs-unlock-home.sh

    remainder redacted
    10 changes: 10 additions & 0 deletions zfs-unlock-home.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/bin/bash

    # Adjust to match your dataset
    ZFS_DATASET="trident/home/michael"

    # Only try if dataset is encrypted and not mounted
    if ! zfs get -H -o value mounted "$ZFS_DATASET" | grep -q "yes"; then
    echo "$PAM_AUTHTOK" | zfs load-key "$ZFS_DATASET"
    zfs mount "$ZFS_DATASET"
    fi