How to transfer apt keyring to another Debian based distribution

  • Post last modified:February 1, 2021
  • Reading time:4 mins read

Initially, when I started my Linux journey, I used to switch from one distribution to another. It was interesting a few days later, and I feel monotonous to add GPG Key again to Install various software.

It isn’t enjoyable to find GPG keys again and add them one by one for all packages.

I need to find some solution through which I can take backup or move the key to another computer, and I asked Mr. Redfield, and he shows me how to move apt key-ring and Import to other systems.

Today I’m going to share the same concept of how you can also transfer apt-key.

What is apt-key?

apt-key It is a Linux-utility for Debian-based distribution used to verify the downloaded packages via apt install. Besides verifying keys, it also helps to add, delete, list, and export public keys.

The default location where all the keyring get stored is /etc/apt/trusted.gpg

What is the GPG key? A GPG (GNU Privacy Guard) key is a security mechanism that verifies the file is genuine.

Export apt-key

For Instance, I have another Ubuntu 20.04 desktop on my home, and I need to export the apt-key ring from my personal laptop. So, I can easily Install all my packages without adding a keyring whenever I install my laptop packages on my desktop.

Step 1: Export key

Open terminal in your base system or from where you want to copy apt-key ring file. In Ubuntu, you can use Ctrl + Alt +T to access the terminal.

In the terminal, type the following command to export apt-keys:

$ apt-key exportall > trusted-keys

Using stdout, you can easily export all the public keys to a file name called trusted-keys off course; you can use a different file name.

How to save the command output in Linux Terminal?

Verify whether apt-key is exported successfully using cat or ls command

$ cat trusted-keys

Output
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBFit2ioBEADhWpZ8/wvZ6hUTiXOwQHXMAlaFHcPH9hAtr4F1y2+OYdbtMuth
lqqwp028AqyY+PRfVMtSYMbjuQuu5byyKR01BbqYhuS3jtqQmljZ/bJvXqnmiVXh
38UuLa+z077PxyxQhu5BbqntTPQMfiyqEiU+BKbq2WmANUKQf+1AmZY/IruOXbnq
L4C1+gJ8vfmXQt99npCaxEjaNRVYfOS8QcixNzHUYnb6emjlANyEVlZzeqo7XKl7
UrwV5inawTSzWNvtjEjj4nJL8NsLwscpLPQUhTQ+7BbQXAwAmeHCUTQIvvWXqw0N
-----END PGP PUBLIC KEY BLOCK-----

Step 2: Copy apt-key to another computer

Once we export the apt-key, we need to move exported apt-key file to another system for that you can use any medium such as thumb drive, email or SCP commands.

In case you don’t know what the SCP command is. SCP is ssh based utility that helps to transfer a file over the network using SSH protocol.

How to install OpenSSH server in Ubuntu

$ scp trusted-key [email protected]:/home/
  • scp a command utility to transfer file
  • trusted-key it is a file that contains exported keys
  • shen user in my remote computer following with remote IP address to check IP address use hostname -I
  • : use to distinguishing between remote and local computers
  • /home path where we need to copy the file.

Learn more about SCP command.

Step 3: Import apt-key

Next, we need to import a trusted-key to our new System. For that, Open a terminal and go to the location where you copied the trusted-key and pass the following commands.

$ sudo apt-key add trusted-keys

In the response of above command you will receive a simple message

OK

After the update, you can install software from your official repository without any fuss to find the GPG key.

Wrap-up

That’s all to export, copy and import apt-key ring file. If you face any issue while following the article, please drop the comment below, and we will try to resolve it.

If you know any other way to resolve this issue, you can share it with our readers too.

Like what you read? Please share it with others.
  • 8
    Shares
guest
0 Comments
Inline Feedbacks
View all comments