OpenSSHとは
OpenSSH(Open Secure Shell)は、SSHプロトコルのオープンソース実装で、OpenBSDプロジェクトが開発しています。Linux、macOS、BSD、Windows 10以降に標準搭載されており、サーバー管理のデファクトスタンダードです。
主要コンポーネント
- ssh:SSHクライアント
- sshd:SSHサーバー(デーモン)
- ssh-keygen:鍵ペア生成
- ssh-agent:鍵の管理とパスフレーズキャッシュ
- scp/sftp:ファイル転送
- ssh-copy-id:公開鍵の登録
基本的な使用例
# 鍵ペア生成(Ed25519推奨)
ssh-keygen -t ed25519 -C "your_email@example.com"
# 公開鍵をサーバーに登録
ssh-copy-id user@server.example.com
# ポートフォワーディング(ローカル→リモート)
ssh -L 8080:localhost:80 user@server.example.com
# 逆ポートフォワーディング
ssh -R 8080:localhost:80 user@server.example.com
# SSHエージェントの使用
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
セキュリティ設定(/etc/ssh/sshd_config)
# パスワード認証を無効化(鍵認証のみ)
PasswordAuthentication no
# ルートログインを禁止
PermitRootLogin no
# 許可するユーザーを限定
AllowUsers admin developer
# 古いアルゴリズムを無効化
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org
HostKeyAlgorithms ssh-ed25519,rsa-sha2-512
