Ubuntu Desktop and most of its variants does not come with SSH server installed by default. Ubuntu Server on the other hand already have SSH server installed automatically during system installation.

OpenSSH server packages are already available in Ubuntu's default apt repository. You can easily install OpenSSH server on Ubuntu and its variants using apt at the terminal.

Tutorial video:

Install SSH server on Ubuntu:

  1. Open terminal from the application launcher or via the <ctrl> + <alt> + <t> keyboard shortcut.
  2. 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.
  3. Install openssh-server package.
    $ sudo apt install --assume-yes openssh-server 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      ncurses-term openssh-sftp-server ssh-import-id
    Suggested packages:
      molly-guard monkeysphere rssh ssh-askpass
    The following NEW packages will be installed:
      ncurses-term openssh-server openssh-sftp-server ssh-import-id
    0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
    ##### snipped
  4. Allow ssh traffic from the firewall (optional).
    $ sudo ufw allow ssh

    Ubuntu does not disable ssh traffic by default so it's only required if you've configured your firewall to drop ssh traffic.

That's all you need to do to have functioning ssh server on your Ubuntu machine. Optionally you can do the followings once you have it installed:

  • 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.
  • Start the ssh service if it's not already started.
    $ sudo systemctl start ssh
  • 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.
  • 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.
  • Configure SSH server options by editing the configuration file using your favorite editor.
    $ sudo vi /etc/ssh/sshd_config
  • SSH service will need to be restarted or reloaded for the changes to take effect.
    $ sudo systemctl restart ssh

Guide compatibility:

Operating System
Ubuntu 16.04 LTS (Xenial Xerus)
Ubuntu 16.10 (Yakkety Yak)
Ubuntu 17.04 (Zesty Zapus)
Ubuntu 17.10 (Artful Aardvark)
Ubuntu 18.04 LTS (Bionic Beaver)
Ubuntu 18.10 (Cosmic Cuttlefish)
Ubuntu 19.04 (Disco Dingo)
Watch online courses:
Leave a comment:
Share!