【问题标题】:Generate public ssh key from private key从私钥生成公共 ssh 密钥
【发布时间】:2021-02-24 00:08:01
【问题描述】:

我有私有 ssh (id_rsa) 密钥。

如何从中生成公钥?

【问题讨论】:

    标签: linux ssh


    【解决方案1】:

    -y 选项输出公钥。来自ssh-keygen 命令的linux手册:

    -y ----这个选项会读取一个私有的OpenSSH格式文件并打印 一个 到标准输出的 OpenSSH 公钥。

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

    附带说明,公钥的注释丢失了。我有一个需要评论的网站(Launchpad?),所以您需要编辑 ~/.ssh/id_rsa.pub 并将评论附加到第一行,评论和关键数据之间有一个空格。一个示例公钥如下所示。

    ssh-rsa AAAA..../VqDjtS5 ubuntu@ubuntu
    

    如果您希望通过脚本方式添加评论并将 pubkey 添加到您的 authorized_keys 文件中,您可以这样做...

    ssh-keygen -y -f ~/.ssh/id_rsa    | \
        sed 's/$/ comment-goes-here/' | \
        tee ~/.ssh/id_rsa.pub         | \
        tee -a authorized_keys
    

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 1970-01-01
      • 2022-01-13
      • 2019-10-12
      • 2016-09-15
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多