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

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.


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

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