Skip to main content
サイバーセキュリティ2026年7月4日7 min read

Linux/Windowsサーバー強化: セキュアな設定のためのステップバイステップガイド

Rudra Chauhan, Senior Systems Architect

Linux/Windowsサーバー強化: セキュアな設定のためのステップバイステップガイド

Linux/Windowsサーバー強化: セキュアな設定のためのステップバイステップガイド

サーバーのセキュリティは、脅威の知識に基づいて進化する連続的なプロセスです。このガイドでは、LinuxとWindowsの両方のプラットフォームでSSH、TLS、ファイアウォール、HTTPセキュリティヘッダーの最も重要な攻撃面を強化し、すべてを繰り返しリスク軽減ワークフローで結び付けることで、セキュアな設定のためのステップバイステップガイドを提供します。

SSHデーモン設定 - セキュアな接続のためのベストプラクティス

直接回答: sshdを強化するには、古いプロトコルを無効化し、キーベースの認証を強制し、アクセスを制限し、強力な暗号化のデフォルトを適用します。

コア強化ステップ (Linux)

bash
# /etc/ssh/sshd_config – すべてのファイルを置き換えまたはこれらの行を追加
Port 2222                                 # 非標準ポートは自動スキャンを減らす
Protocol 2
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
AuthenticationMethods publickey
AllowUsers alice bob@192.0.2.0/24          # ユーザーとソースCIDRによる制限
MaxAuthTries 3
LoginGraceTime 20
ClientAliveInterval 300
ClientAliveCountMax 2
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com

リロード: systemctl reload sshd

Windows OpenSSHサーバー (Win32-OpenSSH)

powershell
# C:\ProgramData\ssh\sshd_config
Port 2222
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey
AllowUsers alice,bob
MaxAuthTries 3
LoginGraceTime 20
ClientAliveInterval 300
ClientAliveCountMax 2
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256

サービスを再起動する: Restart-Service sshd

クイックリファレンステーブル – SSH強化パラメータ

パラメータ推奨値理由
Port2222 (または1024以上)ボットスキャンからのノイズを減らす
PermitRootLoginno直接root侵害を防ぐ
PasswordAuthenticationnoキーベース認証を強制する
AuthenticationMethodspublickeyMFAスタイルの制御を確実にする
Cipherschacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com現代のAEAD暗号のみを使用する
KexAlgorithmscurve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256前向きセキュアなキーエクスチェンジを使用する
AllowUsersalice bob@192.0.2.0/24最小権限のネットワークセグメントを制限する

ツールチップ: SSH Config Generator を使用して、準備ができた sshd_config を生成し、sshd -t を使用してシンタックスを検証します。


セキュアなSSL/TLS設定 – 暗号化のためのベストプラクティスの実装

直接回答: TLS 1.2 + 1.3 のみを展開し、強力な暗号化スイートを使用し、HSTS、OCSPスタンピング、証明書透明性を有効化し、証明書の有効性を強制します。

Nginx例 (Linux)

nginx
# /etc/nginx/conf.d/ssl-hardening.conf
server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    # プロトコル & 暗号化スイート
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256';
    ssl_prefer_server_ciphers off;

    # OCSPスタンピング
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 1.1.1.1 8.8.8.8 valid=300s;
    resolver_timeout 5s;

    # HSTS (1 年、サブドメインを含む、プリロード)
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

    # セキュリティヘッダ (次のセクション参照)
    include /etc/nginx/security-headers.conf;
}

IIS (Windows) – PowerShell強化

powershell
# TLS 1.0/1.1 を無効化し、1.2/1.3 を有効化
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server' -Name 'Enabled' -Value 0
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server' -Name 'Enabled' -Value 0
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Name 'Enabled' -Value 1
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Name 'Enabled' -Value 1

# 暗号化スイートを制限 (例: AES-GCM & CHACHA20 だけ)
$ciphers = @(
    'TLS_AES_256_GCM_SHA384',
    'TLS_CHACHA20_POLY1305_SHA256',
    'TLS_AES_128_GCM_SHA256'
)
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers' -Name 'Functions' -Value ($ciphers -join ',')

# HSTS を有効化 (web.config に追加)
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

参照

  • IETF RFC 7519 – JSON Web Token (JWT) を使用した無状態認証; これらのトークンは、TLS保護されたチャンネルを通じてのみ送信されるようにする。

ファイアウォールルール – iptables、nftables、ufw、Windowsファイアウォールを使用したセキュアなネットワークアクセスを構成する

直接回答: デフォルト拒否ポジションを採用し、必要なインバウンドポート (SSH、HTTPS、管理) を許可し、落とされたパケットをログ化して監査します。

Linux – nftables (現代、原子)

bash
#!/usr/sbin/nft -f
flush ruleset

table inet filter {
    chain input {
        type filter hook input priority 0; policy drop;
        iif "lo" accept
        ct state established,related accept
        # SSH (カスタムポート)
        tcp dport 2222 ct state new limit rate 5/minute accept
        # HTTP/HTTPS
        tcp dport {80,443} accept
        # ICMP (レート制限)
        icmp type echo-request limit rate 1/second accept
        # ログ & 落とし
        log prefix "DROP_IN: " level info
    }
    chain forward {
        type filter hook forward priority 0; policy drop;
    }
    chain output {
        type filter hook output priority 0; policy accept;
    }
}

Linux – UFW (Ubuntu/Debian向け)

bash
ufw default deny incoming
ufw default allow outgoing
ufw allow 2222/tcp comment 'SSH強化ポート'
ufw allow 80,443/tcp comment 'Webトラフィック'
ufw limit 2222/tcp comment 'SSHレート制限'
ufw enable

Windowsファイアウォール – PowerShell (ドメイン/プライベートプロファイル)

powershell
# 基準値をリセット
Set-NetFirewallProfile -All -DefaultInboundAction Block -DefaultOutboundAction Allow -NotifyDisplayEnabled False

# SSH (カスタムポート) を許可
New-NetFirewallRule -DisplayName "Allow SSH 2222" -Direction Inbound -Protocol TCP -LocalPort 2222 -Action Allow -Profile Domain,Private -Enabled True

# HTTP/HTTPS を許可
New-NetFirewallRule -DisplayName "Allow HTTP/HTTPS" -Direction Inbound -Protocol TCP -LocalPort 80,443 -Action Allow -Profile Domain,Private -Enabled True

# 落とされたパケットをログ化
Set-NetFirewallProfile -All -LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log" -LogMaxSizeKilobytes 4096 -LogAllowed False -LogBlocked True -LogIgnored True

ツールチップ: Firewall Rule Generator を使用して、環境に合った iptablesnftablesufw、または Windows ファイアウォール コマンドを生成します。


セキュリティヘッダ – CSP、HSTS、その他の重要なヘッダを実装する

直接回答: HTTP応答にすべてのヘッダを実装する: Content-Security-PolicyStrict-Transport-SecurityX-Content-Type-OptionsX-Frame-OptionsReferrer-PolicyPermissions-PolicyCross-Origin-Opener-Policy

Nginxスニペット (/etc/nginx/security-headers.conf)

nginx
# Content Security Policy – アセットのソースを調整する
add_header Content-Security-Policy
    "default-src 'self';
     script-src 'self' 'nonce-$request_id' https://cdn.example.com;
     style-src  'self' 'nonce-$request_id' https://fonts.googleapis.com;
     img-src    'self' data: https://cdn.example.com;
     font-src   'self' https://fonts.gstatic.com;
     connect-src 'self' https://api.example.com;
     frame-ancestors 'none';
     base-uri 'self';
     form-action 'self';"
    always;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
add_header Cross-Origin-Opener-Policy "same-origin" always;
add_header Cross-Origin-Resource-Policy "same-origin" always;

Apache (/etc/apache2/conf-available/security-headers.conf)

apache
Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'nonce-%{UNIQUE_ID}e' https://cdn.example.com; style-src 'self' 'nonce-%{UNIQUE_ID}e' https://fonts.googleapis.com; img-src 'self' data: https://cdn.example.com; font-src 'self' https://fonts.gstatic.com; connect-src 'self' https://api.example.com; frame-ancestors 'none'; base-uri 'self'; form-action 'self';"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
Header always set Cross-Origin-Opener-Policy "same-origin"
Header always set Cross-Origin-Resource-Policy "same-origin"

IIS – web.config ( <system.webServer> 内に追加)

xml
<httpProtocol>
  <customHeaders>
    <add name="Content-Security-Policy" value="default-src 'self'; script-src 'self' 'nonce-{RANDOM}' https://cdn.example.com; style-src 'self' 'nonce-{RANDOM}' https://fonts.googleapis.com; img-src 'self' data: https://cdn.example.com; font-src 'self' https://fonts.gstatic.com; connect-src 'self' https://api.example.com; frame-ancestors 'none'; base-uri 'self'; form-action 'self';" />
    <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload" />
    <add name="X-Content-Type-Options" value="nosniff" />
    <add name="X-Frame-Options" value="DENY" />
    <add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
    <add name="Permissions-Policy" value="geolocation=(), microphone=(), camera=()" />
    <add name="Cross-Origin-Opener-Policy" value="same-origin" />
    <add name="Cross-Origin-Resource-Policy" value="same-origin" />

トラブルシューティングチェックリスト

このガイドは役に立ちましたか?

このガイドのトラブルシューティングまたはテストをしていますか?

TeksolvrはDNS設定の検査、DKIM証明書の検証、ポート開放テスト、サーバーブラックリストの確認、計算のための97の無料ツールを提供しています。