0

Related to this question about SSH public key for using multiple Github accounts, I'm a bit afraid that the SSH public key I registered in Github might be the one I mispasted. The format of the text I pasted in the SSH public key form is like this:

ssh-rsa [Many characters 1]/[Many characters 2]/[Many characters 3]/[Many Characters 4]/[Many characters 5] myUsername@DESKTOP-XXXXXXX

I'm afraid that the text above holds the directory name of my computer myUsername@DESKTOP-XXXXXXX at the end. Is it correct format of SSH public key? I know nothing about SSH but I just felt a bit weird that the security key has the directory name of the user's computer at the end. I'm guessing I have to trim the directory name after [Many characters 5].

jazzGeek
  • 95
  • 2
  • 9
  • When you paste the key and confirm to add it, Github is supposed to check if it's a valid key. – ElpieKay Mar 05 '21 at 08:52
  • See [RSA Public Key format](https://stackoverflow.com/q/12749858/1256452). (Is this a duplicate question? I'm hesitant to suggest closing it as one, yet) Edit: see also [How to store/retrieve RSA public/private key](https://stackoverflow.com/q/1193529/1256452) (ignore the accepted answer, scroll down to the higher-upvoted one) – torek Mar 05 '21 at 10:00

2 Answers2

0

My id_rsa.pub key has more '/' than what you showed above. The last field that you seem concerned is just a comment to help you identify your key. ssh-keygen -C ... which defaults to user@host. If you are concerned about a copy/paste mistake, compare a checksum of both (on linux sum, md5sum etc).

Allan Wind
  • 23,068
  • 5
  • 28
  • 38
0

An OpenSSH key does not contain any information about a directory of your computer. The format is as follows:

keytype base64-data optional-comment

The key type specifies the type of the key. In your case, it's an RSA key. The second chunk is the actual contents of the key with Base64 encoding. That means it may contain uppercase and lowercase letters, numbers, and the characters + and /, possibly ending with one or more = characters. The last part is an optional comment, which by default is in the format user@host.

What data is encoded in the second portion depends on the key type, but in an RSA key, it contains the type of the key, the modulus N, and the exponent E, each preceded by a four-byte length. The latter two components are large integers that are not intrinsically identifying.

When you send this key to someone or add it to GitHub, you must preserve the key type and the Base64-encoded data completely without modifying it. The Base64 data is just an encoding of the raw data underneath, and it may have any number of slashes, including zero. You don't have to include the comment, and you may modify it at will, but the other parts must not be modified. So if you don't want to include the name of your computer, just omit that portion when you copy it.

bk2204
  • 64,793
  • 6
  • 84
  • 100