How To Install and Enable SSH on Ubuntu Linux

This post will guide you how to install SSH server on your Ubuntu or Debian based system from the command line. How do I install SSH client or enable SSH on Ubuntu Linux system.

How To Install and Enable SSH on Ubuntu Linux 1

What is SSH?


Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Typical applications include remote command-line, login, and remote command execution, but any network service can be secured with SSH.

sshd (OpenSSH Daemon) is the daemon program for ssh. sshd can be configured using command-line options or a configuration file (by default sshd_config(5)); command-line options override values specified in the configuration file.

ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network.

Installing OpenSSH Server on Ubuntu


If you want to setup a ssh server on your Ubuntu Linux system, and you need to install the openssh-server package by running the following command, type:

$ sudo apt install openssh-server

Outputs:

[email protected]:~$ sudo apt install 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 39 not upgraded.
Need to get 637 kB of archives.
After this operation, 5,316 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04 [248 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 openssh-sftp-server amd64 1:7.6p1-4ubuntu0.3 [45.6 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 openssh-server amd64 1:7.6p1-4ubuntu0.3 [333 kB]
Get:4 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 ssh-import-id all 5.7-0ubuntu1.1 [10.9 kB]
Fetched 637 kB in 0s (1,423 kB/s)
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 184235 files and directories currently installed.)
Preparing to unpack .../ncurses-term_6.1-1ubuntu1.18.04_all.deb ...
Unpacking ncurses-term (6.1-1ubuntu1.18.04) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a7.6p1-4ubuntu0.3_amd64.deb ...
Unpacking openssh-sftp-server (1:7.6p1-4ubuntu0.3) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a7.6p1-4ubuntu0.3_amd64.deb ...
Unpacking openssh-server (1:7.6p1-4ubuntu0.3) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.7-0ubuntu1.1_all.deb ...
Unpacking ssh-import-id (5.7-0ubuntu1.1) ...
Setting up ncurses-term (6.1-1ubuntu1.18.04) ...
Setting up openssh-sftp-server (1:7.6p1-4ubuntu0.3) ...
Setting up ssh-import-id (5.7-0ubuntu1.1) ...
Setting up openssh-server (1:7.6p1-4ubuntu0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.29) ...

Once the openssh-server package is installed, and SSHd service have started and enabled on your ubuntu system. And you can verify the installation by running the following command:

$ sudo systemctl status sshd

Outputs:

[email protected]:~$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-10-09 04:20:22 EDT; 52s ago
Main PID: 10102 (sshd)
Tasks: 1 (limit: 1121)
CGroup: /system.slice/ssh.service
└─10102 /usr/sbin/sshd -D

Oct 09 04:20:22 devops-ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Oct 09 04:20:22 devops-ubuntu sshd[10102]: Server listening on 0.0.0.0 port 22.
Oct 09 04:20:22 devops-ubuntu sshd[10102]: Server listening on :: port 22.
Oct 09 04:20:22 devops-ubuntu systemd[1]: Started OpenBSD Secure Shell server.

If you need to start/stop/restart SSHd service on your Ubuntu system, and you can use the following commands:

$ sudo systemctl start sshd
$ sudo systemctl stop sshd
$ sudo systemctl restart sshd

Installing OpenSSh Client on Ubuntu


If you want to log into a remote machine on your ubuntu system, and you need to install the openssh-client package with the following command:

$ sudo apt install openssh-client

Outputs:

[email protected]:~$ sudo apt install openssh-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
keychain libpam-ssh monkeysphere ssh-askpass
The following NEW packages will be installed:
openssh-client
0 upgraded, 1 newly installed, 0 to remove and 39 not upgraded.
Need to get 614 kB of archives.
After this operation, 4,162 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 openssh-client amd64 1:7.6p1-4ubuntu0.3 [614 kB]
Fetched 614 kB in 0s (1,688 kB/s)
Selecting previously unselected package openssh-client.
(Reading database ... 184193 files and directories currently installed.)
Preparing to unpack .../openssh-client_1%3a7.6p1-4ubuntu0.3_amd64.deb ...
Unpacking openssh-client (1:7.6p1-4ubuntu0.3) ...
Setting up openssh-client (1:7.6p1-4ubuntu0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
[email protected]:~$

Once the installation of ssh client finishes, you can use the ssh command to log into a remote machine for executing commands, type:

$ ssh [email protected]
$ ssh dev[email protected]

Configuring SSH on Ubuntu


Now you have installed SSH Server and client on your Ubuntu system, and you can now configure it. You can change the default SSH port from 22 to another port number. or you can also enable root user login by configuring a configuration file using your vim text editor.

For example, you want to change the default port number from 22 to 2048, just open up the ssh configuration file by running the following command:

$ sudo vim /etc/ssh/sshd_config

then you need to find and change the following line from:

# Port 22

to

Port 2048

save and close the file.

You still need to configure your UFW firewall to allow the newly SSH port number 2048, type:

$ sudo ufw allow 2048

Outputs:

[email protected]:~$ sudo ufw allow 2048
Rules updated
Rules updated (v6)

Now you can restart SSHD service for the changes to take effect with the following command:

$ sudo systemctl restart sshd

Conclusion


You should know that how to install and configure SSH Server from the command line in your Ubuntu or Debian based systems.

 

You might also like:

Sidebar



back to top