4

When ssh-keygen -b 4096 creates a key pair, the public key (id_rsa.pub) looks like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDW6AL7knzbwEdPJR+QzMxuVEKI34+cNXX4xi7BF1xhNuI48T3xxB3C7utCXRc+jUzHY7aKmgrj8oWxtoqyS2MRLitBgYjcY9dEAJzay8os5RmdmwANHLsD4FAq6ONEq6wp+D0Mgs0sPGtzpgbpJ+ntxl59yv97G737M3yMXM4/DR20womomvdjeMPU7FDPTxrwxfgzmHQCwf/nTfLigv+ggbXMjJz+FBcZPhGFftn/XeuFskNx3+wJcLQXUplWHaDNoKyxWJjc2FCUjmg1iIHvFo29ppXwQEIPXHnrCjj3TFZ4dVgjTUtx+5W8lXR1GTuUAFRymDMmPeeqV9nJT83mu6H5kdpJ2nNRZPO8km+TMUXRxmzousMFiPq9tL9IAnXGq1MHwpWGZPdqR9hLOa7ESJtcZXcHf/vhqMEDvM2BxEVgEwMGuiSZfezC2PAg//jth1ft7C6nncRVQA16Z7m6gu74CuJj3/LZPisbSCAx+QdAUi0s28JnvlpFf+7UCXy2OBBJKEe3MzsmdUR8vZ8CqL5Sw+LLpt8XCKtcHxBQKkFu/ChsW3TYIhqQFA9mIX2jMTR8wO6C8TSa44lTNxTZclXlAyKy9DMT84Oj+GoK6ArETHqeExssN4Aw/f9oYbr2l9UJfu4kpjs3qWY0DkTPs6TZr7NwRiGPY6ZDD73uww== user@host

What are the practical consequences if I manually edit this public key, changing host to a different host name - so that user@host becomes user@differenthost? Will the key still work in the usual manner?

2 Answers2

5

Changing the base64 encoded partion will break the key... it will either become invalid or not be the pair of the private key anymore.

Changing the text at the end - user@host - is fine. This is the key's comment, and can be set while generating the key with the -C flag:

ssh-keygen -C me@mypc
Attie
  • 20,734
3

The part after public key is an optional comment.

In general, you can edit it any way you like. It does not even have to have the user@host format.


Though some uses of this syntax may impose more strict rules.

For example, when using this to setup a public key authentication in Google Compute Engine console, the comment matters. It has to be a username you want to use the key with.