How to Install, Configure and Enable SSH in Linux?

The Secure Shell (SSH) is a process to access another computer through a secure and two-way encrypted communication system over the internet. If SSH service is enabled in Linux, you can use the SSH protocol (port 22 service) as an FTP (File Transfer Protocol) server or, you can get remote access to another computer. Using SSH service enables data transfer and connection in encrypted form. If you want to maintain your linux servers remotely, you must know how to enable and configure the SSH service in Linux.

The SSH service works with end-to-end encryption, where one end-user has a public key, and another user holds a private key. Data transmission can occur when both users enter the right encryption keys. The SSH functions through the terminal command-line interface.

Lets Decryptinfo about SSH service installation, configuration, and enable

Installing the SSH Service on Ubuntu Linux

The SSH service is by default installed in all Linux or Unix-like operating systems. You can check whether the SSH service is installed inside your Linux machine or not by checking the SSH version. If you find your Ubuntu has an SSH installed, you are good to go. If you cannot find the secure shell service in your Ubuntu Linux, you can install it by the apt-get install command.
To check whether SSH service is installed on machine or not can easily commute with following command:

$ ssh -V

Install the Openssh Server package with the terminal shell command. The process is as follows

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install openssh-server

Enable SSH on Red Hat Linux and CentOS

Red Hat also uses the port 22 to establish SSH service. You may also need to allow the firewall access for SSH service on CentOS and Red Hat Linux.

# dnf install openssh-server
# yum install openssh-server
# systemctl start sshd
# systemctl status sshd
# systemctl enable sshd
firewall-cmd –zone=public –permanent –add-service=ssh

Enabling SSH on Fedora Linux

Fedora Linux also uses port 22 to establish secure shell connections.

#rpm -qa | grep openssh-server
#dnf install -y openssh-server;
#systemctl status sshd
#ss -lt
#systemctl start sshd.service;
#systemctl stop sshd.service;
#systemctl disable sshd.service;

Commands of SSH Service on Linux
After installation of the SSH service, now check the system status, enable the SSH service, and get started with the secure shell system

# systemctl status ssh
# service ssh status
# systemctl enable ssh
# systemctl start ssh
# systemctl stop ssh


Firewall updation to allow SSH service

The firewall system will monitor all the incoming and outgoing networks of your device.

# ufw allow ssh
# ufw enable
# ufw status


Configuring Port Forwarding for SSH Service on Linux

The dynamic port forwarding, and the remote port forwarding system through the SSH service on Linux. To enable port forwarding, we need to check the configuration file of SSH service. We can find the SSH configuration file under the root/etc/ssh directory.
Open the file sshd_config and changed the value of PermitTunnel to yes, and the GatewayPorts to yes. Then save the script file. After configuring the SSH script, you must have to restart the SSH service on your Linux machine.

$vim /etc/ssh/sshd_config
$ vim ~/.ssh/config
$ vim $HOME/.ssh/config
$ sudo vim /etc/ssh/sshd_config

GatewayPorts yes

$ sudo systemctl restart sshd
$ sudo service sshd restart


Connect any remote system enabled with SSH service

open the terminal shell and type ssh then type your username@ssh_service_destination.


For remote port forwarding, the same procedure of SSH service in Linux can be used, add the -f-N  syntax before the server name will do the process execute in the background.

You can also set dynamic and local port forwarding through the SSH service in Linux.

$ ssh -f -N -R 5000:localhost:3000
$ ssh -f -N -D 1080
$ ssh -L test
$ ssh -R 5900:localhost:5900 test



Visual Like below:


Enabling & Authorizing the SSH Service

The systemctl command to start, stop, enable, disable, and restart the SSH service

# systemctl stop ssh
# systemctl start ssh
# systemctl enable ssh
# service ssh restart
, , , , , , , ,

2 Replies to “How to Install, Configure and Enable SSH in Linux?”

Leave a Reply