复制 ssh 私钥文件

Duplicating an ssh private key file

我在~/.ssh/id_rsa下有一个私钥。 运行 ssh-keygen -l -f ~/.ssh/id_rsa 确认密钥有效。

我正在尝试创建另一个包含此密钥的文件。例如,

cp ~/.ssh/id_rsa ~/.ssh/id_rsa.dupe
chmod 0400 ~/.ssh/id_rsa (to make permissions the same for both files)

但是当我 运行 ssh-keygen -l -f ~/.ssh/id_rsa.dupe 时,我得到 ~/.ssh/id_rsa.dupe is not a key file.

这是预期的行为。 ssh-keygen -l 指的是 public 密钥文件,根据其文档:

  -l     Show fingerprint of specified public key file.

如果要生成私钥并生成public密钥,可以使用-y来实现:

ssh-keygen -y -f ~/.ssh/id_rsa.dupe >~/.ssh/id_rsa.dupe.pub
ssh-keygen -l -f ~/.ssh/id_rsa.dupe.pub