Skip to content

Instantly share code, notes, and snippets.

@ergoz
Forked from angela-d/gpg-key-migration.md
Created September 3, 2025 17:14
Show Gist options
  • Save ergoz/4515bb658c6344126d0fea154716e102 to your computer and use it in GitHub Desktop.
Save ergoz/4515bb658c6344126d0fea154716e102 to your computer and use it in GitHub Desktop.

Revisions

  1. @angela-d angela-d created this gist Apr 1, 2018.
    56 changes: 56 additions & 0 deletions gpg-key-migration.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    # Migrate GPG Keys from One Workstation to Another #

    Replace **[your key]** with your key ID

    To obtain your key ID
    ```bash
    gpg --list-secret-keys --keyid-format LONG
    ```

    Which returns something like
    ```bash
    /home/angela/.gnupg/pubring.kbx
    -------------------------------
    sec rsa4096/[your key] 2018-03-30 [SC]
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    uid [ unknown] angela (KEY NAME) <user@domain>
    ssb rsa4096/ABCDEFGHIJKL 2018-03-30 [E]

    ```

    After the key size `rsa4096/` is your key ID.

    ***

    Export the key in preparation to move it
    ```bash
    gpg --export -a [your key] > gpg-pub.asc
    ```

    Prepare the secret key for migration (if password protected, you'll be prompted to enter it)
    ```bash
    gpg --export-secret-keys -a [your key] > gpg-sc.asc
    ```

    Find them
    ```bash
    ls -l gpg*.asc
    ```

    Drag the key pair from the current directory to your USB stick or however else you move them.


    Once on the new machine, import them
    ```bash
    gpg --import gpg-pub.asc
    ```

    If password protected, you'll be prompted to enter it
    ```bash
    gpg --import gpg-sc.asc
    ```

    If you need to adjust the trust level
    ```bash
    gpg --edit-key [your key]
    ```