Ubuntu 20.04 で SSHサーバを構築する


はじめに

Ubuntu 20.04 で SSHサーバを構築するためのメモ。

環境

$ hostnamectl status
   Static hostname: ---
         Icon name: computer-container
           Chassis: container
        Machine ID: ---
           Boot ID: ---
    Virtualization: lxc
  Operating System: Ubuntu 20.04.2 LTS
            Kernel: Linux 5.4.0-67-generic
      Architecture: x86-64

インストール

openssh-server をインストール。

$ sudo apt install openssh-server

SSHサーバを起動

$ sudo systemctl start ssh

rootユーザのSSHログインを禁止する場合

/etc/ssh/sshd_config に記述されている、PermitRootLogin の設定を下記に変更。

こうすることで、rootユーザはSSH経由でログインできないがコンソールからはログイン可能。

PermitRootLogin prohibit-password 

パスワード認証を無効化する場合

/etc/ssh/sshd_config に記述されている、PasswordAuthentication の設定を下記に変更。

PasswordAuthentication no

参考

1.5. OPENSSH のセキュリティーの強化