5.2. OpenSSH サーバーの設定および起動

お使いの環境と OpenSSH サーバーの起動に必要となる基本設定には、以下の手順を使用します。デフォルトの RHEL インストールを行うと、sshd デーモンがすでに起動し、サーバーのホスト鍵が自動的に作成されることに注意してください。

前提条件

  • openssh-server パッケージがインストールされている。

手順

  1. 現行セッションで sshd デーモンを開始し、ブート時に自動的に起動するように設定します。

    # systemctl start sshd
    # systemctl enable sshd
  2. デフォルトの0.0.0.0 (IPv4) または :: とは異なるアドレスを指定するには、以下を行います。(IPv6) /etc/ssh/sshd_config 設定ファイルの ListenAddress ディレクティブ、および低速な動的ネットワーク設定を使用するには、network-online.target ターゲットユニットの依存関係をsshd.service ユニットファイルに追加します。これを行うには、以下の内容で /etc/systemd/system/sshd.service.d/local.conf ファイルを作成します。

    [Unit]
    Wants=network-online.target
    After=network-online.target
  3. /etc/ssh/sshd_config 設定ファイルの OpenSSH サーバーの設定がシナリオの要件を満たしているかどうかを確認します。
  4. 必要に応じて、/etc/issue ファイルを編集して、クライアント認証を行う前に OpenSSH サーバーに表示される welcome メッセージを変更します。以下に例を示します。

    Welcome to ssh-server.example.com
    Warning: By accessing this server, you agree to the referenced terms and conditions.

    Banner オプションが /etc/ssh/sshd_config でコメントアウトされておらず、その値に /etc/issue が含まれていることを確認します。

    # less /etc/ssh/sshd_config | grep Banner
    Banner /etc/issue

    ログインに成功すると表示されるメッセージを変更するには、サーバーの /etc/motd ファイルを編集する必要があります。詳細は、pam_motd の man ページを参照してください。

  5. systemd 設定を再読み込みし、sshd を再起動して変更を適用します。

    # systemctl daemon-reload
    # systemctl restart sshd

検証

  1. sshd デーモンが実行していることを確認します。

    # systemctl status sshd
    ● sshd.service - OpenSSH server daemon
       Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
       Active: active (running) since Mon 2019-11-18 14:59:58 CET; 6min ago
         Docs: man:sshd(8)
               man:sshd_config(5)
     Main PID: 1149 (sshd)
        Tasks: 1 (limit: 11491)
       Memory: 1.9M
       CGroup: /system.slice/sshd.service
               └─1149 /usr/sbin/sshd -D -oCiphers=aes128-ctr,aes256-ctr,aes128-cbc,aes256-cbc -oMACs=hmac-sha2-256,>
    
    Nov 18 14:59:58 ssh-server-example.com systemd[1]: Starting OpenSSH server daemon...
    Nov 18 14:59:58 ssh-server-example.com sshd[1149]: Server listening on 0.0.0.0 port 22.
    Nov 18 14:59:58 ssh-server-example.com sshd[1149]: Server listening on :: port 22.
    Nov 18 14:59:58 ssh-server-example.com systemd[1]: Started OpenSSH server daemon.
  2. SSH クライアントを使用して SSH サーバーに接続します。

    # ssh user@ssh-server-example.com
    ECDSA key fingerprint is SHA256:dXbaS0RG/UzlTTku8GtXSz0S1++lPegSy31v3L/FAEc.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'ssh-server-example.com' (ECDSA) to the list of known hosts.
    
    user@ssh-server-example.com's password:

関連情報

  • sshd(8) および sshd_config(5) の man ページ。