ssh-keygen - 如何使用特定用户名设置 rsa 密钥

发布于 2024-11-17 13:00:33 字数 470 浏览 4 评论 0原文

我刚刚安装了 ubuntu,想使用 bitbucket/github 设置它的 rsa 密钥。当我 ssh-keygen 时,密钥会按应有的方式生成,

ssh-rsa AA...yBEz3pLL georgemauer@ubuntu

除了用户名部分之外,它完全可用。在我之前生成的每个 rsa 密钥中,用户名部分都会读取我的电子邮件地址:

ssh-rsa AA...yBEz3pLL [email protected]

不,这不是主要障碍,但如果我没有正确理解这一点,它会让我发疯。如何使用 rsa 密钥和我选择的电子邮件用户名生成?

I just installed ubuntu and would like to set its rsa keys up with bitbucket/github. When I ssh-keygen the keys are generated as they should be

ssh-rsa AA...yBEz3pLL georgemauer@ubuntu

which is perfectly usable except the username part. In every rsa key I've generated previously, the username section read my email address:

ssh-rsa AA...yBEz3pLL [email protected]

No, it's not a major impediment but if I don't get this right it will drive me crazy. How, do I generate with rsa keys with an email username of my choice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-11-24 13:00:33

使用 -C 选项通过您的密钥提供新注释。这是一个示例:

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ./my-ssh.key

Use the -C option to provide a new comment with your key. Here is a sample:

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ./my-ssh.key
放血 2024-11-24 13:00:33

说明:一般来说,ssh 公钥中的最后一个字符串是一条注释,默认配置为您的user@host。您可以通过添加 -C 参数来覆盖此注释并编辑此字符串。

例如在默认行为中,假设 - 如果您的 Linux 主机名是 Ubuntu 并且您的用户名是 john.doe 当您观看公钥执行 cat ~/.ssh/id_rsa.pub 时,您会看到如下内容:

ssh-rsa <someReallyBigToken>== john.doe@ubuntu

文档:

ssh-keygen 默认情况下将以 OpenSSH 特定格式写入密钥。
这种格式是首选,因为它可以更好地保护密钥
休息并允许存储密钥
私钥文件本身中的注释。 关键注释可能有助于识别关键评论初始化为
创建密钥时“user@host”,但是
可以使用 -c 选项进行更改。

解决方案:覆盖此注释并使用 -C 参数进行注释。

ssh-keygen -t rsa -b 4096 -C message-in-a-bottle
cat ~/.ssh/id_rsa.pub

// output:
ssh-rsa <someReallyBigToken>== message-in-a-bottle

Explanation: In general, the last string in your ssh public key would be a single comment which in default configured to your user@host. You can override this comment by adding -C argument and edit this string.

For example In default behaviour, lets say that - if your linux hostname is Ubuntu and your user name is john.doe while you watch your public key performing cat ~/.ssh/id_rsa.pub you would see something like this:

ssh-rsa <someReallyBigToken>== john.doe@ubuntu

Documentation:

ssh-keygen will by default write keys in an OpenSSH-specific format.
This format is preferred as it offers better protection for keys at
rest as well as allowing storage of key
comments within the private key file itself. The key comment may be useful to help identify the key. The comment is initialized to
``user@host'' when the key is created, but
can be changed using the -c option.

Solution: override this comment and use -C argument for comment.

ssh-keygen -t rsa -b 4096 -C message-in-a-bottle
cat ~/.ssh/id_rsa.pub

// output:
ssh-rsa <someReallyBigToken>== message-in-a-bottle
很酷不放纵 2024-11-24 13:00:33
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]

我使用此命令生成 SSH 密钥,以生成 GitHub、GitLab 和 GCP。
此处是使用用户名创建 SSH 密钥的文档。

ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]

I use this command for generating the SSH key for generating GitHub, GitLab, and GCP.
Here is the documentation for creating an SSH key with a username.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文