Git
SSH
RSA

Git BashでSSHキーを生成する

More than 1 year has passed since last update.

Git BashでSSHキーを生成

※Git Bashはgitをインストールすると使えます→Git for Windows

ssh-keygenで生成
※このときオプションで -t rsa (RSA暗号化方式)で生成すること

sola@note-pc MINGW64 ~
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/sola/.ssh/id_rsa):
Created directory '/c/Users/sola/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/sola/.ssh/id_rsa.
Your public key has been saved in /c/Users/sola/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:2ddfgxrdAghKc***********************g21mAE3sdT4 sola@note-pc
The key's randomart image is:
+---[RSA 2048]----+
|    ..o=O+*oX=++o|
|    o+ +o+ X+*oo+|
~~~略~~~
|                 |
|                 |
+----[SHA256]-----+

sola@note-pc MINGW64 ~
$



ssh-keygenのhelp

sola@note-pc MINGW64 ~
$ ssh-keygen --help
ssh-keygen: unknown option -- -
usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]
                  [-N new_passphrase] [-C comment] [-f output_keyfile]
       ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
       ssh-keygen -i [-m key_format] [-f input_keyfile]
       ssh-keygen -e [-m key_format] [-f input_keyfile]
       ssh-keygen -y [-f input_keyfile]
       ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
       ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
       ssh-keygen -B [-f input_keyfile]
       ssh-keygen -D pkcs11
       ssh-keygen -F hostname [-f known_hosts_file] [-l]
       ssh-keygen -H [-f known_hosts_file]
       ssh-keygen -R hostname [-f known_hosts_file]
       ssh-keygen -r hostname [-f input_keyfile] [-g]
       ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
       ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
                  [-j start_line] [-K checkpt] [-W generator]
       ssh-keygen -s ca_key -I certificate_identity [-h] [-U]
                  [-D pkcs11_provider] [-n principals] [-O option]
                  [-V validity_interval] [-z serial_number] file ...
       ssh-keygen -L [-f input_keyfile]
       ssh-keygen -A
       ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
                  file ...
       ssh-keygen -Q -f krl_file file ...



生成したSSHキーの強度を確認

sola@note-pc MINGW64 ~
$ ssh-keygen -l -f ~/.ssh/id_rsa.pub
2048 SHA256:Wej8Grz3/Px+**********+CjUtRtKd0QFSHPxz79Uk sola@note-pc (RSA)



RSAの1024bitsの鍵は使用するのはやめておいた方がいいみたいです
以下参考
- お前らのSSH Keysの作り方は間違っている - Qiita
- GitHubユーザーのSSH鍵6万個を調べてみた - hnwの日記