How To Install SSH Server Ubuntu 18.04 Bionic Beaver

Step 1: Install & Configure SSH Server

1.1 Install SSH server

sudo apt-get install openssh-server -y

1.1.a Edit SSH server configuration file

sudo nano /etc/ssh/sshd_config

1.1.b Remove the hashtag from the port statement

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

Exit and Save

1.2 Restart SSH daemon

sudo systemctl restart ssh

 1.3 Verify status

sudo systemctl status ssh
root@srv6:/# sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: active (running) since Fri 2018-11-02 19:18:05 UTC; 5s ago
  Process: 2113 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 2119 (sshd)
    Tasks: 1 (limit: 1113)
   CGroup: /system.slice/ssh.service
           └─2119 /usr/sbin/sshd -D

Nov 02 19:18:05 srv6 systemd[1]: Starting OpenBSD Secure Shell server...
Nov 02 19:18:05 srv6 sshd[2119]: Server listening on 0.0.0.0 port 22.
Nov 02 19:18:05 srv6 sshd[2119]: Server listening on :: port 22.
Nov 02 19:18:05 srv6 systemd[1]: Started OpenBSD Secure Shell server.

SSH server is read to be used on port 22

Step 2: Configure SSH Server

2.1 Change SSH Server port

sudo nano /etc/ssh/sshd_config

2.1.a Change the port number

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 888
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

Exit and Save

2.1.b Restart the SSH service

sudo systemctl restart ssh

2.1.c Verify status

sudo systemctl status ssh
root@srv6:/# sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: active (running) since Fri 2018-11-02 19:21:13 UTC; 7s ago
  Process: 2185 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 2198 (sshd)
    Tasks: 1 (limit: 1113)
   CGroup: /system.slice/ssh.service
           └─2198 /usr/sbin/sshd -D

Nov 02 19:21:13 srv6 systemd[1]: Starting OpenBSD Secure Shell server...
Nov 02 19:21:13 srv6 sshd[2198]: Server listening on 0.0.0.0 port 888.
Nov 02 19:21:13 srv6 sshd[2198]: Server listening on :: port 888.
Nov 02 19:21:13 srv6 systemd[1]: Started OpenBSD Secure Shell server.

SSH server is ready to be used on port 888

2.2 Disable the option to login in directly as root via SSH

sudo nano /etc/ssh/sshd_config

2.2.a Change the PermitRootLogin parameter to no

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes
# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

Exit and Save

2.2.b Restart the SSH service

sudo systemctl restart ssh

Useful Commands

SSH Service status

sudo systemctl status ssh

Restart SSH service

sudo systemctl restart ssh

Stop SSH service

sudo service ssh stop

Start SSH service

sudo service ssh start

Disable SSH service next boot

sudo systemctl disable ssh

Enable SSH service next boot

sudo systemctl enable ssh

Donate