How to install SSH server in Ubuntu VM (Virtualbox or VMware player)

Ubuntu Desktop version do not install SSH server by default. Here are the steps to install and configure SSH server in Ubuntu 20.04 Desktop (or in Server if required)

sudo apt-get install openssh-server

Example:

[email protected]:~$ sudo apt-get install openssh-server
...
Reading package lists... Done
Building dependency tree       
...
Do you want to continue? [Y/n] 
  • Provide your password, if prompted.
  • Give Y to continue with the installation steps.

OpenSSH Enable and start Service

After installation, you need to make sure the ssh service has been enabled and started.

Enabling the service, so that OpenSSH server will be started automatically after Ubuntu reboot.

[email protected]:~$ 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

For now, just after the installation, you have to start the SSH service. (Or reboot the system)

[email protected]:~$ sudo systemctl start ssh
[email protected]:~$ 

How to verify SSH service status in Ubuntu

[email protected]:~$ 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 xxxxx xxxxx 16:20:29 IST; 10min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 2453 (sshd)
      Tasks: 1 (limit: 2312)
     Memory: 1.0M
     CGroup: /system.slice/ssh.service
             └─2453 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Jan 04 16:20:29 codetryout systemd[1]: Starting OpenBSD Secure Shell server...
Jan 04 16:20:29 codetryout sshd[2453]: Server listening on 0.0.0.0 port 22.
Jan 04 16:20:29 codetryout sshd[2453]: Server listening on :: port 22.
Jan 04 16:20:29 codetryout systemd[1]: Started OpenBSD Secure Shell server.
[email protected]:~$ 

Note: Step by step instruction for installing OpenSSH (SSH server) in Ubuntu and or in Ubuntu Virtual Machine, this is suitable for your test/development environments. For production systems, advanced steps must be followed to secure the SSH server.