aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-04-20 17:01:34 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-04-20 17:01:34 +0200
commit29cac8f112c9fff801224d6b5717a01a23d98616 (patch)
treef52b4c60e667bb81159caac8040167eb30558dea
parent36d01e1b9782805296ab7d9b7a12ce476d295951 (diff)
Additional File Permissions and FlagsHEADmain
Set some additional file permissions and flags for the generated key file (to make it less accessible to other users and prevent it from being included in backups).
-rwxr-xr-xkeyfile.sh16
1 files changed, 14 insertions, 2 deletions
diff --git a/keyfile.sh b/keyfile.sh
index b3a028a..c9dd31f 100755
--- a/keyfile.sh
+++ b/keyfile.sh
@@ -2,7 +2,9 @@
set -euo pipefail
-mkdir -p "$HOME/.local/share/keepass"
+KEYFILE="$HOME/.local/share/keepass/trezor.key"
+
+mkdir -m 0700 -p "$(dirname "$KEYFILE")"
# We use the SLIP-0016 master key as the key file for our KeePass database,
# with a more appropriate key.
@@ -13,4 +15,14 @@ KEY='Unlock vault.kdbx?'
VALUE='2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'
"${TREZORCTL:-trezorctl}" encrypt-keyvalue --address "$ADDRESS" --prompt always "$KEY" "$VALUE" \
- | xxd -r -p > "$HOME/.local/share/keepass/trezor.key"
+ | xxd -r -p > "$KEYFILE"
+
+# Restrict permissions on the file. We also set the `nodump` flag which some
+# software will respect and omit from backups (notably, `tarsnap` which I use).
+chmod 0400 "$KEYFILE"
+if command -v chattr &>/dev/null; then
+ chattr +d "$KEYFILE"
+fi
+if command -v chflags &>/dev/null; then
+ chflags nodump "$KEYFILE"
+fi