3
0

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 1 year has passed since last update.

秘密鍵・公開鍵の作成方法について ~ssh-keygen~

Posted at

前提

秘密鍵・公開鍵の作り方には複数の方法がありますが、今回はssh-keygenを用いた方法で作成したのでご紹介します。

コード全体

$ cd .ssh
$ssh-keygen -b 2048 -t rsa -f cloudshellkey

Generating public/private rsa key pair.
cloudshellkey already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in cloudshellkey.>Your public key has been saved in cloudshellkey.pub.
The key fingerprint is:
SHA256:u7kjkwEYeHGuWk0/nkPwA6IAtzSB/nLf0fk+VZI1B9s  
yo@ba7195bd66e9
The key's randomart image is:
+---[RSA 2048]----+
|.o*o.         .. |
|+oo=           =.|
|o.oo=         + E|
|.o.=.=       o . |
|. + ..* S .   o  |
| + o o.= +   .   |
|. o . =oo . .    |
|     .+o.o o     |
|       o+o...    |
+----[SHA256]-----+


$ls
cloudshellkey  cloudshellkey.pub  known_hosts


$cat cloudshellkey.pub

各コードの説明

①sshディレクトリに移動します。

$cd.ssh

②公開鍵・秘密鍵の生成を行います。

$ssh-keygen -b 2048 -t rsa -f cloudshellkey

-b 2048     2048ビットで作成する
-t RSA     RSA形式で暗号化することを表します
-f cloudshellkey どのファイルに出力するかを表します

鍵作成の際のオプションは任意です。以下の資料を参考にしました。
(参考)
https://atmarkit.itmedia.co.jp/ait/articles/1908/02/news015.html

③以下のコマンドでファイルをリスト化すると「cloudshellkey」「cloudshellkey.pub」が出来上がっていることがわかります。

$ls
cloudshellkey  cloudshellkey.pub  known_hosts

以下のコマンドでファイルの中身を見ることもできます

$cat cloudshellkey.pub

終わりに

秘密鍵・暗号鍵の説明を文字で読んだ時に難しいと感じていましたが、実際に手を動かしてみると意味が少しずつ分かってきました。
他にも鍵の生成方法はあるので時間がある時に試してみたいと思います。

3
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?