ssh-keygen

ネットワーク

書き方

ssh-keygen -t ed25519 -C "<comment>"

公開鍵と秘密鍵の対を作ります。サーバーに置くのは `.pub` の側だけで、合言葉なしで作った鍵はそのファイル一つあれば誰でもそのまま入れてしまう状態です。

よく使うオプション

オプション意味
-t ed25519Key type. ed25519 is the modern default; rsa needs -b 4096 to be worth using.
-C "you@laptop"A comment so you can tell your keys apart later.
-f <path>Where to write the key, when you want more than one.
-N ""No passphrase. Then the file alone is enough to log in.
-pChange or add the passphrase on an existing key.
-l -f <key.pub>Print the fingerprint, to compare against what a server shows.
-y -f <key>Recreate the public half from a private key.
-R <host>Remove a host from known_hosts after it was rebuilt.

ssh-keygen -t ed25519 -C "jade@laptop"

Create a modern key pair in ~/.ssh.

ssh-keygen -R old.example.com

Fix the "REMOTE HOST IDENTIFICATION HAS CHANGED" warning properly.

ssh-keygen -lf ~/.ssh/id_ed25519.pub

The fingerprint of your public key.

つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. ssh-keygen は何をしますか。

公開鍵と秘密鍵の対を作ります。サーバーに置くのは `.pub` の側だけで、合言葉なしで作った鍵はそのファイル一つあれば誰でもそのまま入れてしまう状態です。

Q. どう打ちますか。

ssh-keygen -t ed25519 -C "<comment>" — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは8個です。全部は man ssh-keygen にあります。このコマンドはネットワークの仲間です。

関連するコマンド

man ページ: man ssh-keygen