'ssh-keygen - how to set an rsa key with a certain username

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?



Solution 1:[1]

Use the -C option to provide a new comment with your key.

Solution 2:[2]

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

Solution 3:[3]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 datasage
Solution 2
Solution 3