How to install SSH server on Ubuntu

Ubuntu Desktop and related variants does not come with SSH server installed by default except for the Server edition. It could however be installed and enabled easily with the following steps via the command line;

  1. Update package list from the repository.
    $ sudo apt update
  2. Install openssh-server package.
    $ sudo apt install -y openssh-server
  3. ssh service should be started and enabled by default after installation. Check to confirm.
    $ sudo systemctl status ssh
    ● ssh.service - OpenBSD Secure Shell server
       Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2018-06-07 11:07:30 +08; 4min 57s ago
     Main PID: 5327 (sshd)
        Tasks: 1 (limit: 2295)
       CGroup: /system.slice/ssh.service
               └─5327 /usr/sbin/sshd -D
    
    Jun 07 11:07:30 host systemd[1]: Starting OpenBSD Secure Shell server...
    Jun 07 11:07:30 host sshd[5327]: Server listening on 0.0.0.0 port 22.
    Jun 07 11:07:30 host sshd[5327]: Server listening on :: port 22.
    Jun 07 11:07:30 host systemd[1]: Started OpenBSD Secure Shell server.
  4. Start the ssh service if it's not already started.
    $ sudo systemctl start ssh
  5. You can disable ssh from running by default during system boot.
    $ sudo systemctl disable ssh
    Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install disable ssh
    Removed /etc/systemd/system/sshd.service.
  6. To enable it back again, run the following command.
    $ sudo systemctl enable ssh
    Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install enable ssh
    Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.