如何更改 RSA 密钥 (SSH) 的注释字段?

ELL*_*BLE 43 ssh private-key

我知道我可以简单地打开公钥并在==s之后更改评论,但是在创建时决定的评论字段是否也存储在私钥中?如果是这样,如何在不从头开始生成全新密钥的情况下更改该字段?

An *_*Vad 39

我在自己搜索更改新 ubuntu 安装中 ssh 密钥中的注释时遇到了这个问题。

然后我在手册页 ( man ssh-keygen) 中进行了搜索,答案就在那里 -

ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]

-c      Requests changing the comment in the private and public key files.
        This operation is only supported for RSA1 keys and keys stored in the
        newer OpenSSH format.  The program will prompt for the file containing 
        the private keys, for the passphrase if the key has one, and for the
        new comment.
Run Code Online (Sandbox Code Playgroud)

所以,对我来说,我所要做的就是

ssh-keygen -c -C "my new comment" -f ~/.ssh/my_ssh_key
Run Code Online (Sandbox Code Playgroud)

附带说明:ssh-keygen可用于更改用于保护密钥文件的密码,包括删除密码。


LAF*_*ica 6

我刚刚创建了一个 RSA 密钥ssh-keygen -t rsa -b 4096,没有通过,没有注释(所以标准注释)。我已将其上传到 GitHub,然后更改了评论。无需重新上传,密钥在更改之前和之后都有效,并且在从 GitHub 删除后停止工作(尽管如果它被缓存并仅因此而工作,我还没有测试过)。

会话日志:

lafk-T470% ssh-keygen -c -f ~/.ssh/id_rsa -C "a new comment"           
Comments are only supported for keys stored in the new format (-o).
lafk-T470% ssh-keygen -c -f ~/.ssh/id_rsa -C "a new comment" -o
Key now has no comment
The comment in your key file has been changed.
lafk-T470% vim ~/.ssh/id_rsa.pub                                       
lafk-T470% tail -1 ~/.ssh/id_rsa.pub                      
ssh-rsa  AAAAB3NzaC1yc2EAAAADAQABAAACAQCocnoRyM7Oy5XA0dLIaiHHQiPnimJvXifliTZI7OX5lqkACsZmUL/D7kUV2uPDyyPZ6lm0UGUHXhOw2QjStQ6ubPRFOKWQyNDkemaQAJtHPYTkT4pGHbsddyko3SRG0Vp4A9CSLRLJXVGuGn1UpfjB/AD0aUcLWVJdgWDuovR09t1YsHbakDpDh4a/2JS52Cvg6x9kEGakZK7ffUQZ64yZvqisEH//e7SbYtpHIp4ZdBMSIIsFIBWvqMXZowahvSMbV7MeLFuwt90dMOFiGJIe0n8oPt/ilQ0FTRcEP7UODyLKbESHkZqoGAHKeQ4ZMCCv7T00KtB98HvWylqvzHg2rIpLMHkVcRGjwlaZUlZB5Zxk6dAJ5HHg1irF+05UeIbQ9YQF/0x63KWQvreEcmLrkbnZ++XeF2ipE7M7CfkYhpJ9XbKZBG4pOQIqLio2rBV9c3+y+sPq4BABXdJKAnIX+h3kFrvOVA7Gy9/YxgQfCJ0ZSmaAV08uqMm91GYGRU9lt2Uf/ALqhW0rH93UWUj232w35rY8GtXucWAjtw3zi6QtZsIAStRzT3Br+Qrqv4MrKvEk+4rzswytaYjCGLrsMDYL7hI/YEJh9vv/v3wGvJGAqLDk1FeBL8tdwEMr1eM9JKl5gVkmBa4MdJkNMe4rHwUIidrW8LW2EEBY3DmDTQ== a new comment
lafk-T470% git clone git@github.com:GH_User/a-repository.git
Cloning into 'a-repository'...
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 0), reused 8 (delta 0), pack-reused 0
Receiving objects: 100% (8/8), done.
Run Code Online (Sandbox Code Playgroud)

因此,这适用于以新格式存储的密钥。我的 ServerFault 答案中详细介绍了步骤。

所有操作均在 Xubuntu 18.04 默认 OpenSSH ssh-keygen 上完成。

私钥将会以这种方式发生变化。不是因为它的评论,而是因为它的格式发生了变化。请参阅此处针对专为该比较创建的键的比较。

私钥比较 - 格式已更改

请注意,对于 pub-key,我已经有效地破坏了它,因此 Meld 更好地显示了更改的内容:空格已通过换行符更改(这会破坏格式)。

(损坏)公钥比较,只有评论发生了变化


jhc*_*ced 5

我刚刚做了一个小测试,修改了我的 RSA 私钥的“注释:”行,它似乎在创建密钥时就被修复了。

它是用 Putty 生成的 RSA 密钥,修改密钥中的注释后,密码不起作用,我必须将编辑反转到相同的原始注释才能再次工作。