Keeping track of SSH private keys without comments

SSH public keys support comments (which simply consist of text appended to the end of the key), which makes it easy to identify an otherwise unidentifiable id_rsa.pub file. You can use the comment to store information such as who the key belongs to, when it was created, and what machine it's for.

Private keys appear to lack this feature. ssh-keygen -C comment will generate a keypair with the comment appended to the public key, but the private key will remain uncommented. ssh-keygen has a -c argument that "requests changing the comment in the private and public key files", but

root@kitsune:~# ssh-keygen -c -f id_rsa
Comments are only supported for RSA1 keys.

So it would appear that the SSH2 private key format has no comment field. This is mostly fine as long as one keeps the pair of keys together and in the right place, but the files can get copied and moved around (which might happen when accounts/machines share a key) or overwritten accidentally, and they all have the same name (id_rsa), so one can lose track of which key is which. In the absence of commenting, what are the best practices for keeping private keys organized?

4
задан 21 February 2016 в 22:10
1 ответ

Сохранение закрытого ключа с открытым ключом дает вам возможность увидеть комментарий, хранящийся в общедоступной части, с помощью приведенной ниже команды, но я вижу, что это не то, что вам нужно. Невозможно сохранить комментарий в самом ключе (как вы уже упоминали).

$ ssh-keygen -lf ~/.ssh/id_rsa
2048 SHA256:abcdef[...] [comment] (RSA)

файлы можно копировать и перемещать

Это действительно плохая идея. Вы не хотите, чтобы ваши личные данные перемещались. В идеальном случае у вас должна быть одна пара ключей на каждое устройство, с которого вы подключаетесь. Если вам нужно больше ключей на клиенте, я бы выбрал другое название, например id_rsa-private-github (с соответствующим названием публичной части). При правильной настройке в ~ / .ssh / config и / или ssh-agent в этой настройке нет недостатка.

2
ответ дан 3 December 2019 в 03:55

Теги

Похожие вопросы