SSHの堅牢化と鍵ベース認証
Linuxサーバーで最も攻撃にさらされやすいサービスを保護します。SSHを鍵のみのログインに設定し、危険なデフォルトを無効化して攻撃対象領域を縮小する方法を学びます。
「SSHの堅牢化と鍵ベース認証」はCoddyKit上の無料Linux Networking & TCP/IP for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Networking & TCP/IP for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Harden SSH
SSH is the primary remote-administration channel and a constant target of automated brute-force attacks.
Hardening SSH dramatically reduces the risk of unauthorized access with a handful of configuration changes in /etc/ssh/sshd_config.
Generating a Strong Key Pair
Prefer modern Ed25519 keys over older RSA. Generate a pair with a passphrase for defense in depth.
ssh-keygen -t ed25519 -C 'admin@server'Installing the Public Key
Copy the public key to the server's ~/.ssh/authorized_keys. The helper ssh-copy-id automates this safely.
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@serverDisabling Password Authentication
Once key login works, turn off passwords entirely so brute-force attacks cannot succeed.
In sshd_config:
PasswordAuthentication noChallengeResponseAuthentication noUsePAM yes
PasswordAuthentication noDisabling Root Login
Never allow direct root SSH login. Log in as a normal user and escalate with sudo.
PermitRootLogin noRestricting Users
Limit who may connect with AllowUsers or AllowGroups. Anyone not listed is rejected outright.
AllowUsers admin deployChanging the Default Port
Moving off port 22 will not stop a determined attacker but cuts noisy automated scans considerably.
Remember to update your firewall rules to match.
Port 2222Limiting Authentication Attempts
Tighten the connection handshake to frustrate brute-force tools.
MaxAuthTries 3LoginGraceTime 20MaxStartups 10:30:60
MaxAuthTries 3Adding Fail2ban
fail2ban watches auth logs and temporarily bans IPs after repeated failures, blocking persistent attackers automatically.
sudo apt install fail2ban
sudo systemctl enable --now fail2banTesting Before Disconnecting
Always validate config and keep an existing session open before restarting sshd, so a mistake does not lock you out.
sudo sshd -t && sudo systemctl restart sshVerifying the Hardened Config
Confirm the effective settings the daemon will use with sshd -T, which prints the resolved configuration.
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication'Quick Check
Test your SSH hardening knowledge.
Recap
You have hardened the most exposed Linux service:
- Ed25519 key pairs with passphrases
PasswordAuthentication noandPermitRootLogin no- User restrictions and tightened auth limits
fail2banfor automatic banning- Always
sshd -tand verify before disconnecting
This complements your firewall, VPN, and IDS lessons for layered defense.
よくある質問
「SSHの堅牢化と鍵ベース認証」レッスンは無料ですか?
はい。「SSHの堅牢化と鍵ベース認証」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Networking & TCP/IP for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。
「SSHの堅牢化と鍵ベース認証」で何を学びますか?
Linuxサーバーで最も攻撃にさらされやすいサービスを保護します。SSHを鍵のみのログインに設定し、危険なデフォルトを無効化して攻撃対象領域を縮小する方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Networking & TCP/IP for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Networking & TCP/IP for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Networking & TCP/IP for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「SSHの堅牢化と鍵ベース認証」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Networking & TCP/IP for Developersレッスンでコードを書いて実行できますか?
はい。すべてのLinux Networking & TCP/IP for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 高度なファイアウォールルール(nftables)
- VPNの概念と設定
- ネットワーク侵入検知(IDS)
- SSHの堅牢化と鍵ベース認証