How to Add a Comment to an existing SSH Public Key

Question: I have an existing SSH key (public and private), that was created with ssh-keygen, however now I need to add a comment to that existing key. How can I Add a Comment to an existing SSH Public Key?

Sometimes users need to add a comment to their ssh-key, this is required in colleges, unversities, campus and also on big IT companies where you have multiple employees logging in and out of Unix / Linux servers. In this cases, adding a comment to an existing SSH public key becomes a requirement.

The good thing is you can add a comment to an existing ssh key, you don’t need to generate a new one. Let’s see how to add your comment to the ssh-key you already generated.

Add a comment to an existing SSH Public Key

According to the sshd man page at the ‘authorized_keys’ section, you can put your comments at the end of the ssh-key line:

Bits, exponent, and modulus are taken directly from the RSA host key;
they can be obtained, for example, from /etc/ssh/ssh_host_key.pub. The
optional comment field continues to the end of the line, and is not used.
Lines starting with '#' and empty lines are ignored as comments.

So, to add a comment to an existing ssh-key, you just need to add a space after the key and put enter your comment, as you see below. E.g.

ssh-rsa WupHu98XJpYUZY6pjwL5CILz3XGvdqG8XE08FyKq0EusEMG8FkGXOeKy9YaNAbcBNa2eBZ6GJ0VuE1Aq2WbJWLQkM8Fz4ukVjGs6a/2s/iUp9xUjGcjaVo8T+pdkbFzBZ+mqQamZpSN1hC8fXe/Uty0D
SbhnQ1qanwrOdKP1JV7DUgzehSfAAAAIEAwAyNYxUsGil46gZQea6sfhUnrBwyM6JnEbA6ogfGdS
T2TDn1U5rfTV9UuNHzfoZ4CplVHcl0yvNum9RukEB5+LSTz32+O0U8MYYudGLlBRNj4uqJR91ROwM0lZye7/5YP= MyComment

Now you know how to add a comment to an existing SSH public key to increase the visibility and identify things related to SSH connections and system users who need to login.

Recommended reading:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

Your email address will not be published. Required fields are marked *