When performing an automated server deployment, I can upload and import gpg keys via script. But I cannot trust keys.

I tried

gpg --batch --yes --edit-key keyname trust 5


echo 5 | gpg --batch --yes --edit-key keyname trust -

In non-batch mode it always stops to ask for input. In batch mode it ignores input.

What is the correct syntax?

2 Answers 2


get fingerprint for key "keyname":
FP=$(gpg --list-keys keyname | head -n2 | tail -n1 | tr -d '[:blank:]')

trust key:
echo -e "5\ny\n" | gpg --command-fd 0 --edit-key "$FP" trust

$ fingerprint=`gpg --fingerprint --with-colons [email protected] \
    | awk -F: '/^pub:/ {getline; print $10}'`
$ gpg --quick-sign-key "$b_fingerprint"

Determining a fingerprint is taken from here. A bigger example can be found here.

You must log in to answer this question.

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