重装系统后导入SSH和GPG密钥

以 macOS 为例。

导入 SSH 密钥

macOS 已经内置了 SSH 了,因此我们不必另行安装。准备好先前导出过的 SSH 密钥,在终端下执行命令:

$ ssh-add ./id_rsa

此时可能收到错误:

$ ssh-add id_rsa
Error loading key "id_rsa": invalid format

如果你遇到了这个错误,请参考:

导入 GPG 密钥对

# 建议把文件权限设置为 600
$ gpg --import ./pgp-pubkey-export.txt
gpg: directory '~/.gnupg' created
gpg: keybox '~/.gnupg/pubring.kbx' created
gpg: ~/.gnupg/trustdb.gpg: trustdb created
gpg: KEY INFO imported
gpg: Total number processed: 1
gpg:               imported: 1
$ gpg --allow-secret-key-import --import ./pgp-seckey-export.txt
# Then enter your passphrase
gpg: key INFO not changed
gpg: key INFO: secret key imported
gpg: Total number processed: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1
 

发表评论