Export passwords from the `pass` password manager

passwordscripting

I've been using the pass password manager for a year or so now, and it's awesome, but sometimes I like to test other password managers and then I need my passwords back.

So far I've just been adding them manually as I need them, but if I want to migrate to another password manager I need a script, because I don't have the patience to do it one by one, considering I have near to a hundred (if not more).

Is it possible? Is there already a solution?

I've searched for a solution on and off for the past couple months and haven't been able to find one where it's "just run this script and boom exported".

Is there such a script? If not, what or where should I look into to make one?

Best Answer

You can do this if you are running gpg-agent (and your passphrase is loaded), by looping through the files in your password store and writing them to a separate file.

You do have to strip the leading directories from the path ($PASSWORD_STORE_DIR) and the .gpg extension from each of the files in the subdirectories, but otherwise it is straightforward enough:

#!/usr/bin/env bash
# export passwords to external file

shopt -s nullglob globstar
prefix=${PASSWORD_STORE_DIR:-$HOME/.password-store}

for file in "$prefix"/**/*.gpg; do                           
    file="${file/$prefix//}"
    printf "%s\n" "Name: ${file%.*}" >> exported_passes
    pass "${file%.*}" >> exported_passes
    printf "\n\n" >> exported_passes
done
Related Question