cat /etc/ssh/sshd_config で SSH 設定を確認する
この最後のステップでは、SSH サーバの主要な設定ファイルを調べます。このファイルには、SSH サービスの動作を制御する設定が含まれています。たとえば、どのポートでリスニングするか、どのユーザが接続できるか、セキュリティオプションなどです。
SSH デーモン (sshd) の設定ファイルは通常、/etc/ssh/sshd_config にあります。/etc ディレクトリは、システムの設定ファイルが保存される場所です。
このファイルの内容を表示するには、cat コマンドを使用できます。cat は、ファイルを順番に読み取り、標準出力(ターミナル)に出力する単純なコマンドです。
ターミナルに以下のコマンドを入力し、Enter キーを押します。
cat /etc/ssh/sshd_config
sshd_config ファイルの全内容がターミナルに表示されます。出力には多くの行が含まれ、一部は # で始まり(これはコメントで、システムによって無視されます)、他の行は設定オプションを定義しています。
コメントアウトされていない行(# で始まらない行)を探します。見つかる重要なディレクティブには以下のようなものがあります。
Port 22: これは SSH サーバがリスニングするポートを指定します。デフォルトでは 22 です。
ListenAddress 0.0.0.0: サーバがリスニングする IPv4 アドレスを指定します。
ListenAddress ::: サーバがリスニングする IPv6 アドレスを指定します。
PermitRootLogin prohibit-password: root ユーザが SSH で直接ログインできるかどうかを制御します。
PasswordAuthentication yes: パスワード認証が許可されているかどうかを制御します。
## This is the sshd server system configuration file.
## See sshd_config(5) for more information.
## The systemd service file for sshd uses EnvironmentFile to load
## the SSHD_CONFIG environment variable, setting this to /etc/ssh/sshd_config.
## ...
Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
## Ciphers and keying
#...
## Authentication:
LoginGraceTime 2m
PermitRootLogin prohibit-password
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
## Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#IgnoreRhosts yes
#RhostsRSAAuthentication no
#HostbasedAuthentication no
#...
PasswordAuthentication yes
#PermitEmptyPasswords no
ChallengeResponseAuthentication no
#...
このような設定ファイルを読むことは、Linux サービスを理解し管理するための重要なスキルです。この実験ではファイルを変更しませんが、ファイルの場所と内容を表示する方法を知っておくと非常に便利です。
これで、SSH サービスの状態を確認し、リスニングポートを検証し、設定ファイルを調べることができました。サービス管理とネットワーク検査に関する基本的な Linux コマンドの貴重な経験を積むことができました。
Continue をクリックして実験を完了し、進捗状況を確認しましょう!