Ubuntu Linux install OpenSSH server

How do I install OpenSSH server on Ubuntu Linux version 16.04/18.04/20.04/22.04 LTS?

Introduction: sshd (OpenSSH Daemon or server) is the daemon program for ssh client. It is a free and open source ssh server. ssh replaces insecure rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network such as the Internet. Ubuntu Desktop and minimal Ubuntu server do not come with sshd installed. However, you can easily install SSH server in Ubuntu using the following steps.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Package Manager
OS compatibility Debian  Linux  Mint  Pop!_OS  Ubuntu
Est. reading time 4 minutes

How to install SSH server in Ubuntu

The procedure to install a ssh server in Ubuntu Linux is as follows:

  1. Open the terminal application for Ubuntu desktop.
  2. For remote Ubuntu server you must use BMC or KVM or IPMI tool to get console access.
  3. Type command:$ sudo apt-get install openssh-server
  4. Enable the ssh service by typing:$ sudo systemctl enable ssh
    ## OR enable and start the ssh service immediately ##
    $ sudo systemctl enable ssh --now
  5. Start the ssh service by typing:$ sudo systemctl start ssh
  6. Test it by login into the system using:$ ssh userName@Your-server-name-IP
    $ ssh ec2-user@ec2-aws-ip-here

Let us see all Ubuntu OpenSSH server installation steps in details with config options using remote console or local terminal.

1. Login to remote server using bmc/ipmi/kvm over IP (optional)

I am using OpenPOWER based system called Talos II from Raptor Computing Systems. It is a PowerPC (ppc/ppc64le) based architecture. After a fresh installation of Ubuntu Linux (ppc64le), I found does not come with SSH server installed by default. So here is how to login to bmc server to gain access to the serial console:
$ ssh root@power9-bmc
Run obmc-console-client to get console access to the Ubuntu server console:
# obmc-console-client
How to login to power9 system with openbmc client

2. Ubuntu Linux install OpenSSH server

First update the system using the apt command or apt-get command:
$ sudo apt update
$ sudo apt upgrade

Installing sshd server on Ubuntu Linux

To install openssh-server package, run:
$ sudo apt install openssh-server

Ubuntu Linux install OpenSSH server

Click to enlarge an image

3. Verify that ssh service running

Type the following systemctl command:
$ sudo systemctl status ssh
Check to confirm that OpenSSH server running on Ubuntu
If not running enable the ssh server and start it as follows by typing the systemctl command:
$ sudo systemctl enable ssh
$ sudo systemctl start 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.

4. Configure firewall and open port 22

You must configure the Ubuntu Linux firewall called ufw. Here is how open or allow port 22 when using ufw on Ubuntu:
$ sudo ufw allow ssh
$ sudo ufw enable
$ sudo ufw status

See our “setting up ufw firewall on Ubuntu” guide for more info.

5. Test it

Now you can login from your desktop computer powered by Linux, *BSD, macOS, MS-Windows (putty client) or Unix-like system using the ssh command:
$ ssh vivek@server-ip
$ ssh vivek@power9

How to Enable and test SSH in Ubuntu Linux server
You can install copy and install the public key using ssh-copy-id command for password less login:
$ ssh-copy-id vivek@power9
See “SSH Public Key Based Authentication on a Linux/Unix server” for more info.

Ssh config file

One can create shortcuts for ssh login / client options. For example create a file named ~/.ssh/config as follows:
$ nano ~/.ssh/config
OR
$ vi $HOME/.ssh/config
Append the following to login into my EC2 Ubuntu server at AWS cloud:

Host web01
        HostName aws-ec2-www-server1.cyberciti.biz
        Port 22
        IdentityFile  ~/.ssh/AWS_EC2_Virginia_US_East_Ubuntu_Boxes.pem
        User ubuntu

To log in simply type:
$ ssh web01
See “OpenSSH Config File Examples” for more info.

Conclusion

In this tutorial, you learn how to install the OpenSSH server application at a terminal prompt. Although instructions tested for Power9 (ppc64le) architecture, they should work on Intel AMD64 or ARAM64 server as well. For more info see OpenSSH home page here and how to secure OpenSSH server tutorial here. Make sure you read manual pages too using the man command:
$ man sshd_config

This entry is 6 of 23 in the Linux/Unix OpenSSH Tutorial series. Keep reading the rest of the series:
  1. Top 20 OpenSSH Server Best Security Practices
  2. How To Set up SSH Keys on a Linux / Unix System
  3. OpenSSH Config File Examples For Linux / Unix Users
  4. Audit SSH server and client config on Linux/Unix
  5. How to install and upgrade OpenSSH server on FreeBSD
  6. Ubuntu Linux install OpenSSH server
  7. Install OpenSSH server on Alpine Linux (including Docker)
  8. Debian Linux Install OpenSSH SSHD Server
  9. Configure OpenSSH To Listen On an IPv6 Address
  10. OpenSSH Server connection drops out after few minutes of inactivity
  11. Display banner/message before OpenSSH authentication
  12. Force OpenSSH (sshd) to listen on selected multiple IP address only
  13. OpenSSH Change a Passphrase With ssh-keygen command
  14. Reuse SSH Connection To Speed Up Remote Login Process Using Multiplexing
  15. Check Syntax Errors before Restarting SSHD Server
  16. Change the ssh port on Linux or Unix server
  17. OpenSSH Deny or Restrict Access To Users and Groups
  18. Linux OpenSSH server deny root user access / log in
  19. Disable ssh password login on Linux to increase security
  20. SSH ProxyCommand example: Going through one host to reach server
  21. OpenSSH Multiplexer To Speed Up OpenSSH Connections
  22. Install / Append SSH Key In A Remote Linux / UNIX Servers Authorized_keys
  23. Use ssh-copy-id with an OpenSSH Server Listening On a Different Port

Did you find this article useful?