GnuPG requires all keys you want to use to be imported into a keyring.
If you don't want to import it to your normal keyring, either use another (temporary) keyring, or even a temporary GnuPG home directory (which will also bypass any configuration).
--primary-keyring temporary.gpg to use (and create if necessary) a temporary keyring as default. It will be created in your GnuPG home directory (
~/.gnupg/temporary.gpg by default). Your normal keyring will still be available, but imports will go to the temporary one. Delete it as you want to.
gpg --primary-keyring temporary.gpg --import key.asc
gpg --primary-keyring temporary.gpg --recipient 0xDEADBEEF --encrypt
rm ~/.gnupg/temporary.gpg # can be omitted, not loaded by default
Temporary GnuPG Home Directory
This will also reset all configuration, and might be helpful for testing some stuff. Set
--homedir [folder] or the environment variable
$GNUPGHOME, import the key, perform any operations and then delete the folder as you wish to.
export GNUPGHOME=/tmp/gnupg # Or apply --homedir on each invocation
gpg --import key.asc
gpg --recipient 0xDEADBEEF --encrypt
rm -r $GNUPGHOME # Can be omitted
GnuPG is very picky regarding permissions, you might need to apply stricter permissions to the
$GNUPGHOME folder before being able to perform all operations. Might very well be an option to keep some playground-