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

ざっくり SSH 公開鍵認証方式

Last updated at Posted at 2025-02-20

概要

公開鍵を相互に持ちます。秘密鍵を相手に渡してはいけません。

接続元と接続先のチェックは相互に行われます。

関連するファイルの一般的な配置は以下の通りです。

ファイル 接続元(クライアント) 接続先(サーバー)
クライアント
秘密鍵
(1)
~/.ssh/id_ed25519
なし
クライアント
公開鍵
(1)
~/.ssh/id_ed25519.pub
(2)
~/.ssh/authorized_keys
サーバー
秘密鍵
なし (3)
/etc/ssh/ssh_host_ed25519_key
サーバー
公開鍵
(4)
~/.ssh/known_hosts
(3)
/etc/ssh/ssh_host_ed25519_key.pub

詳細な説明

(1). クライアントの鍵ペアの作成

  • クライアント側で ssh-keygen を実行し、id_ed25519(秘密鍵)と id_ed25519.pub(公開鍵)を作成
コマンド例
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
  • id_ed25519 は秘密として扱い、外部に流出させないこと

(2). 公開鍵のサーバー登録

  • クライアントの id_ed25519.pub をサーバーの ~/.ssh/authorized_keys に追加
コマンド例
cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
  • authorized_keys はサーバーが接続を許可するクライアントの公開鍵リスト

(3). サーバーのホスト鍵の生成

  • SSH サーバーが自己認証するために使用する秘密鍵と公開鍵
  • /etc/ssh/ssh_host_ed25519_key(秘密鍵)および /etc/ssh/ssh_host_ed25519_key.pub(公開鍵)が OpenSSH サーバーインストール時に自動生成
  • 通常は手動で設定不要

(4). クライアントの known_hosts

  • クライアントが接続したことのあるサーバーの公開鍵情報を記録
  • 初回接続時に以下のような警告が表示され、受け入れると ~/.ssh/known_hosts に登録
The authenticity of host 'server.example.com (192.168.1.1)' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
  • known_hosts はサーバーのなりすましを防ぐために利用される

SSH 鍵の選択について(2025年現在)

現在、セキュリティと処理速度の観点から Ed25519 が推奨されています。

古いシステムとの互換性が必要な場合は RSA 4096bit を使用することがあるかもしれません。

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