I'm trying to copy my gpg key from one machine to another

I know what you're talking about

gpg --export ${ID} > public.key
gpg --export-secret-key ${ID} > private.key

Move the files to a new machine and then

gpg --import public.key
gpg: nyckel [ID]: public key [Name, e-mail] was imported
gpg: Total number of treated keys: 1
gpg:                 imported: 1  (RSA: 1)

gpg --allow-secret-key-import private.key
sec  [?]/[ID] [Creation date] [Name, e-mail]
ssb  [?]/[SUB-ID] [Creation date]

All looks good to me, but then.

$ gpg -d [file].gpg
gpg: encrypted with 4096-bit RSA-key, id [SUB-ID], created [Creation date]
  [Name, e-mail]
gpg: decryption failed: secret key not accessible

The error message says that the file has been encrypted with sub-id which appears to be imported by the secret key import (The [SUB-ID] in both messages is the same).

I'm certainly doing something wrong but i don't know

Best Answer


You need to add --import to the command line to import the private key. You need not use the --allow-secret-key-import flag. According to the man page: "This is an obsolete option and is not used anywhere."

gpg --import private.key