Baba Tech Blog

TR EN

Backing Up and Restoring SSH and GPG Keys

Backing Up and Restoring SSH and GPG Keys 🔑#

SSH and GPG keys are critical for authentication and data security. In this article, you will learn how to backup and restore SSH and GPG keys. 💾

1️⃣ Backup#

First, backup your SSH private and public keys to a safe location.

Copy id_rsa and id_rsa.pub files to USB drive:

cp ~/.ssh/id_rsa ~/.ssh/id_rsa.pub /mnt/usb/

Run the following command to identify your GPG key:

gpg --list-secret-keys --keyid-format LONG

The output will look like this:

sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]

The characters after the slash (/) are the ID of your private key. Use this ID to export your private key:

gpg --export-secret-keys 3AA5C34371567BD2 > my-private-key.asc

Now copy the my-private-key.asc file to USB drive:

cp my-private-key.asc /mnt/usb/

2️⃣ Restore 🛠️#

If you need to transfer your SSH and GPG keys to a new system, follow the steps below.

🔹 Restoring SSH Keys#

Copy the id_rsa and id_rsa.pub files from USB drive to ~/.ssh/ directory:

cp /mnt/usb/id_rsa /mnt/usb/id_rsa.pub ~/.ssh/

Set file permissions and ownership:

chown user:user ~/.ssh/id_rsa*
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub

Start SSH Agent:

exec ssh-agent bash

Add your SSH private key to SSH Agent:

ssh-add ~/.ssh/id_rsa

🔹 Restoring GPG Keys#

Import your GPG private key:

gpg --import my-private-key.asc

🎯 Conclusion#

By following these steps, you can securely backup and restore your SSH and GPG keys when needed. 🔒 Make sure to store your backups in a secure environment and prevent unauthorized access! 🚀 ssh-gpg-backup-restore

Webmentions

Likes

  • Loading likes...

Comments & Replies

  • Loading comments...

Comments
Reply via Bluesky

With an account on the Fediverse or Mastodon, you can respond to this post.

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.

Loading comments...