ssh-keygen - how to set an rsa key with a certain username
Solution 1
Use the -C
option to provide a new comment with your key.
Solution 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
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
I use this command for generating ssh key for generating github, gitlab and GCP. Here is the documentation for creating ssh key with a username.
Abhishek
I have been a senior developer with a focus on architecture, simplicity, and building effective teams for over ten years. As a director at Surge consulting I was involved in many operational duties and decisions and - in addition to software development duties - designed and implemented an interview processes and was involved in community building that saw it grow from 20 to about 350 developers and through an acquisition. I was then CTO setting up a dev shop at working closely with graduates of a coding bootcamp on both project work and helping them establish careers in the industry. Currently a Director of Engineering at findhelp.org your search engine for finding social services. I speak at conferences, have mentored dozens of software devs, have written popular articles, and been interviewed for a variety of podcasts and publications. I suppose that makes me an industry leader. I'm particularly interesting in companies that allow remote work and can check one or more of the following boxes: Product companies that help people in a non-trite manner (eg I'm not super interested in the next greatest way to get food delivered) Product companies that make developer or productivity tooling Funded startups that need a technical co-founder Functional programming (especially Clojure or Elixir) Companies trying to do something interesting with WebAssembly
Updated on January 21, 2021Comments
-
Abhishek over 3 years
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?