Install SSH server on Ubuntu

Ubuntu Desktop and most of its variants does not come with SSH server installed by default. It is pre-installed if you're using the Ubuntu Server variant, for example.

You can easily install OpenSSH server on Ubuntu by following these steps at the terminal:

  1. Update apt's package list from the repository.
    $ sudo apt update
    [sudo] password for user:
    ##### snipped
    3 packages can be upgraded. Run 'apt list --upgradable' to see them.
  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.
  7. Configure SSH server options by editing the configuration file using your favorite editor.
    $ sudo vi /etc/ssh/sshd_config
  8. SSH service will need to be restarted or reloaded for the changes to take effect.
    $ sudo systemctl restart ssh

Sign up for Ubuntu Linux Fundamentals - Learn Linux Server with Ubuntu course on Udemy and learn more.

Leave a comment below if this article is outdated or inaccurate and share if you find it useful.


Written by Mohd Shakir Zakaria. Last updated on 2019-03-20