I am trying export subkeys to card for a keyring without any keyboard interaction using the command keytocard. This type of command is the same as addphoto as it requires to edit the keyring with --edit-key

The following code add a photo but password is still required:

local cmd="addphoto\n$var_photo_path\ny\nsave"
echo -e $cmd | gpg2  --command-fd 0 --status-fd 2 --edit-key $keyring_hash_id

I have tried several approach around: gpg asks for password even with --passphrase

I also took into account the option:

--pinentry-mode loopback

as explained here: wiki.archlinux.org:GnuPGUnattended_passphrase

I use Ubuntu with and gpg 2.1.15 with libgcrypt 1.7.2-beta

Anyone knows how avoid any keyboard interaction on these type of command addphoto / keytocard ?

1 Answer 1


You can do the following for addphoto:

echo -e "$cmd" | gpg2  --command-fd 0 --pinentry-mode=loopback --status-fd 2 --edit-key "$keyid"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .