最初の30分: VPSセキュリティ強化チェックリスト
新しいVPSは、IPを取得してから数分以内に最初のSSHプローブを受けます。以下は、私がすべての新規ボックスで実行する正確な手順です — Debian 13向けにコピペ可能で、最後にチェックリスト表があります。
前提: VPSRentoデプロイからの新しいDebian 13イメージ、 root としてSSHでログイン済み、例のIPは 185.220.101.14 — ご自身のものに置き換えてください。合計時間: 約30分。順番通りに実行してください。ステップ2は急ぐとロックアウトされる可能性があります。
1. sudoユーザーを作成する
rootで作業すると、タイプミスがインシデントになります。実ユーザーを作成し、sudoを付与して、そこからすべてを実行してください:
# create the user (you'll set a password — still useful for sudo)
adduser ops
# grant sudo
usermod -aG sudo ops
この時点以降のすべては、特に指定がない限り ops として実行されます。
2. SSHキーのみ — パスワードなし、rootログインなし
パスワード認証は、インターネットに面したボックスにおける最大の穴です。ボットはポート22を認証情報リストで毎日終日叩き続けます。キーを使えば、この攻撃クラス全体が無意味になります。 ご自身のローカルマシンで:
# generate a keypair if you don't have one (ed25519, no passphrase tradeoff is yours)
ssh-keygen -t ed25519 -C "ops@atlas"
# push the public key to the server
ssh-copy-id [email protected]
設定に触れる前に、 新しい ターミナル — ssh [email protected] — 既存のrootセッションは脱出ハッチとして開いたままにしてください。その後、 /etc/ssh/sshd_config:
# /etc/ssh/sshd_config — the three lines that matter
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
# validate the config, then reload (Debian 13 uses ssh.service)
sshd -t && systemctl reload ssh
prohibit-password をフラットな no ではなく編集します。rootは意図的に: rootはワークステーションのキーで認証可能なままにし、プロバイダーコンソールでの復旧に時々役立ちます — ただし、パスワードは誰にも、どこからも決して機能しません。 sshd -T | grep -E 'passwordauthentication|permitrootlogin'.
で確認してください。
3. ファイアウォール: デフォルト拒否、実行中のものだけ許可
apt update && apt install -y ufw
ufw default deny incoming
ufw default allow outgoing
# SSH stays open — add this BEFORE enabling
ufw allow 22/tcp comment 'SSH'
# whatever your box actually serves, e.g.:
ufw allow 80/tcp comment 'HTTP'
ufw allow 443/tcp comment 'HTTPS'
ufw enable
ufw status verbose
Debianのufwは、nftables上の薄くて健全なレイヤーです。ポリシーがセキュリティであり、ルールはその例外にすぎません:
開くすべてのポートには名前と理由が必要です。ポートの用途を説明できないなら、ルールは不要です。
4. fail2ban: ボットを低速化する
apt install -y fail2ban
# /etc/fail2ban/jail.local
[sshd]
enabled = true
port = ssh
maxretry = 5
findtime = 10m
bantime = 1h
systemctl enable --now fail2ban
# watch it work
fail2ban-client status sshd
パスワード認証を無効にすれば、ブルートフォースはすでに死んでいます — しかしfail2banはログを読みやすく保ち、他のすべてを探るスキャナーを禁止します:
5. 自動セキュリティ更新
apt install -y unattended-upgrades
# answer Yes to auto-install updates
dpkg-reconfigure -plow unattended-upgrades
未パッチのCVEは再起動よりも大きなリスクです。Debianのunattended-upgradesはセキュリティ更新を自動でインストールします: /etc/apt/apt.conf.d/50unattended-upgrades のデフォルト設定はセキュリティスイートのみから取得します — サーバーに望ましい動作です: セキュリティ修正は自動、それ以外は選択時に。
6. 実行していないものを無効化する
実行中のすべてのサービスは、パッチが必要な攻撃面です。実際にリッスンしているものを確認してください:
# who is listening, on what, as which process
ss -tulpn
# everything enabled at boot
systemctl list-unit-files --state=enabled
# example: you don't run a print server — nobody does
systemctl disable --now cups
ルール: リスナーの用途を説明できないなら、稼働させる前に調べてください。最小限のVPSRentoイメージでは、 sshd と独自アプリケーション以外はほとんどないはずです。
7. 任意ですが推奨:WireGuard管理プレーン
SSHセキュリティの最強の形は、SSHがインターネットに一切直面しないことです。ボックス上でWireGuardを実行し、SSHをトンネル内のみに許可すれば、ポート22は地球上のすべてのスキャナーから消えます:
apt install -y wireguard
# /etc/wireguard/wg0.conf — minimal management tunnel
# [Interface] Address = 10.8.0.1/24, ListenPort = 51820
# open the tunnel, not the shell
ufw allow 51820/udp comment 'WireGuard'
ufw allow in on wg0 to any port 22 proto tcp comment 'SSH via WG'
ufw delete allow 22/tcp
systemctl enable --now wg-quick@wg0
その後、 ssh [email protected] をトンネル経由で実行し、パブリックIPは正確に1つのUDPポートでのみ応答します。完全なWireGuardウォークスルー(キー、ピア、クライアント設定、電話用QRコード)は 関連ガイド.
10項目のチェックリスト
新しいデプロイのたびに、そしてサービスを追加するたびに、この表を確認してください:
| # | 項目 | 場所 | 確認方法 |
|---|---|---|---|
| 1 | 非rootのsudoユーザー | /etc/passwd | id ops |
| 2 | キーのみのSSH認証 | sshd_config | sshd -T | grep passwordauth |
| 3 | rootパスワードログイン無効化 | sshd_config | sshd -T | grep permitrootlogin |
| 4 | ファイアウォールのデフォルトで受信拒否 | ufw | ufw status verbose |
| 5 | 指定ポートのみ開放 | ufw | ufw status numbered |
| 6 | fail2ban sshd jailがアクティブ | jail.local | fail2ban-client status sshd |
| 7 | セキュリティ更新の自動適用 | apt | systemctl status unattended-upgrades |
| 8 | 説明のつかないリスナーがないこと | — | ss -tulpn |
| 9 | WireGuard経由の管理(任意) | wg0.conf | wg show |
| 10 | ハードニング後のスナップショット | クライアントエリアのアドオン、 $1.99/月 | サービス → お使いのVPS → スナップショット |
項目10には一言:まずハードニング、次にスナップショット、この順序です。クリーンでハードニングされたボックスのスナップショットは、将来のあらゆるミスに対するロールバックです。毎日のオフサイトスナップショットは $1.99/月 のアドオンで、 クライアントエリアにあります。予防に30分、保険にワンクリック。