如何备份和恢复密码和密钥?

我正在在一台新机器上安装Ubuntu。我该如何备份所有密码和密钥(又称为Seahorse或GNOME Keyring)中的条目,以便将它们转移到新机器上?

1个回答

Keyring数据存储在几个地方:

  • "密码"(GNOME Keyring数据)存储在~/.local/share/keyrings

  • "Secure Shell"数据(SSH密钥)存储在~/.ssh

  • "PGP密钥"(包括GPG密钥)存储在~/.gnupg

您需要备份和恢复这些文件夹。最好不要使用闪存驱动器进行操作(见下面的说明)。在恢复文件夹时,请确保权限设置正确(见下面的说明)。

关于闪存驱动器的注意事项

应该避免使用闪存驱动器来存储/传输密钥,即使是临时的,因为从闪存驱动器中删除的数据很容易被恢复,除非你采取预防措施,比如对驱动器进行加密除非你采取预防措施。如果你有网络连接,通过ssh进行传输既方便又安全。

关于权限的注意事项

在恢复文件夹时,它们需要正确的所有权权限,你可以按照以下步骤应用:

chown --recursive USERNAME:USERNAME ~/.ssh
chmod 755 ~/.ssh
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa.pub
# repeat the last two for other public/private pairs
# you may need to "service ssh restart" after changing these values

chown --recursive USERNAME:USERNAME ~/.gnupg
chmod 700 ~/.gnupg
chmod 600 ~/.gnupg/*
# for any subfolders, you need to apply 700 to the folder
# and 600 to the files in that subfolder:
# chmod 700 ~/.gnupg/subfolder
# chmod 600 ~/.gnupg/subfolder/*

参考资料: