Bobay Stack

Security boundaries / 2026-10-12

Pulling Plaintext Passwords Out of Scripts: A Cleanup That Started With askpass.bat

A .bat file held an SSH password; the same one sat in sixteen notes across many machines. Three steps: keys, login method, one storage location.

4 MIN READ BY BOBAY.TOP Updated 2026-10-17 ↖ All notes
Pulling Plaintext Passwords Out of Scripts: A Cleanup That Started With askpass.bat

It started small: an askpass.bat file had the SSH password written in plaintext so it could log in without interaction, and then it sat in a synced directory for a long time.

Following that thread, the problem turned out to be far bigger than this one file: the same password appeared in sixteen notes, covering PVE nodes, databases, several VPS instances, panels and sync services. That means if any one note leaks, that whole set of machines is lost.

Step 1: Generate the keys first, then talk about migration

Don't change the server side before generating keys — that intermediate state is awkward: password auth is off, the key isn't installed yet, and the only way in is the console.

ssh-keygen -t ed25519 -a 100 -C "<purpose>-<host>" -f ~/.ssh/id_ed25519_<host>

One key per purpose, with the purpose and host name in the filename, so that when something leaks later you know which key to revoke.

ssh-copy-id is the least hassle for injecting the public key; for PVE containers you can write it directly on the host:

pct exec <vmid> -- mkdir -p /root/.ssh
pct exec <vmid> -- sh -c 'echo "<public-key>" >> /root/.ssh/authorized_keys'
pct exec <vmid> -- chmod 700 /root/.ssh

After installing, test a passwordless login once — confirm you can get in, then change the server side.

Step 2: Turn off password login

# /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin prohibit-password

Before changing anything, make sure of the following:

  • The console (VNC / Lightsail browser terminal) works — that's the only fallback.
  • Don't log out of the current session; keep it open as a verification window.
  • Run sshd -t first to check the config syntax; if sshd -t reports an error, don't restart.

Once sshd -t passes, systemctl reload sshd (use reload rather than restart, so established sessions aren't dropped).

Step 3: Collect the remaining passwords into a single location

Not every service can switch to keys: panel logins, databases, and object storage API keys can only use a password or token. These need a single storage location, and it has to meet three conditions:

  1. Not inside a synced directory (or the sync target itself is encrypted).
  2. Not under any path that goes into Git.
  3. In notes, leave only a pointer: write "see <key-name> in the secrets file", never the value.

During the cleanup I made a table, confirmed one by one which locations had held the same password, then replaced them one place at a time. That table itself must not stay in your notes — delete it when you're done.

Review checklist

  • [ ] One separate key per purpose, with IdentityFile bound per Host in ~/.ssh/config
  • [ ] PasswordAuthentication no and the console is reachable
  • [ ] All panel and database passwords rotated, old values gone from every file
  • [ ] No plaintext credentials left in synced directories or backup archives
  • [ ] On machines where a password ever went into shell history, clean ~/.bash_history and .zsh_history

The last item is easy to overlook: that mysql -p<password> line in history is just as bad as writing it to a file in plaintext.

Four places credentials scatter to

  1. Hardcoded in scripts (mysql -pPASSWORD)
  2. shell history (~/.bash_history)
  3. Config files (.env, config.php)
  4. Backup archives (vzdump backups containing /root/.ssh)

2 and 4 are the easiest to miss. A plaintext password in history stays there until HISTFILE is cleared; a key inside a backup archive gets copied to every copy of that backup.

Tightening order

  1. Stop history from recording sensitive commands: HISTCONTROL=ignorespace, and put a space before the command
  2. Change config files to read environment variables
  3. Keep all keys in ~/.ssh/ with mode 600
  4. Exclude credential directories before backing up
# exclude sensitive directories from vzdump
vzdump 101 --exclude-path /root/.ssh --exclude-path /root/.config

One-shot cleanup

# find suspected hardcoded secrets in scripts
grep -rnE "(password|passwd|token|secret)\s*=\s*['\"][^'\"]{6,}" /root /opt --include=*.sh --include=*.py
# strip credential lines from history
sed -i '/sshpass/d;/mysql -p/d' ~/.bash_history

The second one is a delete operation — run cp ~/.bash_history /tmp/bh.bak before executing it.

One principle

If you can avoid a password, avoid it. SSH uses keys, the database uses a socket plus local auth, APIs use short-lived tokens. Passwords only show up where you have to hand one to someone else, and they get rotated after every use.

One line to sum up: writing "where it breaks" next to "how to verify it" is more useful than writing only the config — config can be copied, the order of judgment can't.

SSHkey-based authcredential managementincident response

References

OpenSSH ssh_config manual ↗ Proxmox pct documentation ↗