3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ssh-keygenの公開錠コメントを変えたいやつなんていない

Last updated at Posted at 2021-02-04

業務にて関係部署に公開鍵を渡す機会があることも、ないこともない!

しかし、公開錠のコメントを下のように私用のメールアドレスで作ってしまったそんなあなた!

.pub
ssh-rsa AAAAB3NzaC1yXXXXXXXXXXXXXXXXXXXXXXXXX== stbtkhr@sample.com

もっとわかりやすく鍵の中身を変えずに、コメントのみを会社のメルアドとかにしたい!

いろいろ調べたが検索してみても欲しいやつがなかった。

とりあえずコマンドには、manや!

man ssh-keygen

Too many arguments.
usage: ssh-keygen [-q] [-b bits] [-C comment] [-f output_keyfile] [-m format]
                  [-N new_passphrase] [-t dsa | ecdsa | ed25519 | rsa]
       ssh-keygen -p [-f keyfile] [-m format] [-N new_passphrase]
                   [-P old_passphrase]
       ssh-keygen -i [-f input_keyfile] [-m key_format]
       ssh-keygen -e [-f input_keyfile] [-m key_format]
       ssh-keygen -y [-f input_keyfile]
       ssh-keygen -c [-C comment] [-f keyfile] [-P passphrase]
//以下省略

     -C comment
             Provides a new comment.

     -c      Requests changing the comment in the private and public key files.  The program will prompt for the file containing the private keys, for the passphrase if the key has one, and for the new comment.

と書いてあったので、以下を実行してみる。

ssh-keygen -c -C "test"

これだけ。そうすると以下のように変わるはず。

.pub
ssh-rsa AAAAB3NzaC1yXXXXXXXXXXXXXXXXXXXXXXXXX== test

見事最後のコメント部分だけ変更になった。

vimで変更するのも考えたが、(ないと思うけど)破壊する恐れがあったので、ssh-keygenで行うのが安全かな?
ここまで至るまでmanをよく読まず適当に試した結果、今まで登録していた秘密鍵すら変更する失敗を犯しました。

そんな失敗をしないようにしましょうね!みなさま!

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?