How to install ssh on Linux

Secure shell (SSH) is a network protocol providing shell services on a remote machine via a secure channel. OpenSSH is an open-source implementation of the ssh protocol, allowing encrypted communication over a network via a suite of software. If you would like to set up SSH on Linux, you can install OpenSSH as follows.

To install OpenSSH and auto-start OpenSSH server on CentOS or RHEL:

$ sudo yum -y install openssh-server openssh-clients
$ sudo service sshd start
$ sudo chkconfig sshd on

To install OpenSSH and auto-start OpenSSH server on Fedora:

$ sudo yum -y install openssh-server openssh-clients
$ sudo service sshd start
$ sudo systemctl enable sshd.service

To install OpenSSH and auto-start OpenSSH server on Ubuntu or Debian:

$ sudo apt-get install openssh-server openssh-client

The above commands will install OpenSSH server and client, and start OpenSSH server automatically upon boot.

On Debian/Ubuntu, if for any reason OpenSSH server does not get started automatically upon boot, you can run the following command to explicitly add ssh to boot time service.

$ sudo update-rc.d ssh defaults

If you would like to configure OpenSSH server, you can edit system-wide OpenSSH configuration file located at /etc/ssh/sshd_config.

There are a couple of OpenSSH options you may be interested in:

Port 22

By default, sshd listens on port 22 to listen for incoming ssh connections. By changing the default ssh port, you may be able to avert various automated attacks from hackers.

ListenAddress 192.168.1.1

If your machine has more than one physical network interface, and you would like to specify the interface on which sshd binds, you can use the ListenAddress option. This option helps improve security by limiting incoming SSH connections via a specific interface only.

HostKey /etc/ssh/ssh_host_key

The HostKey option specifies where the private host key is located.

PermitRootLogin no 

The PermitRootLogin option tells whether root can log in to the system via ssh.

AllowUsers alice bob

Using the AllowUsers option, you can selectively disable ssh service for particular Linux users. You can specify multiple users separated by space.

Once you have modified /etc/ssh/sshd_config, make sure to restart ssh service.

To restart OpenSSH on Ubuntu or Debian:

$ sudo /etc/init.d/ssh restart

To restart OpenSSH on CentOS, Fedora or RHEL:

$ sudo service sshd restart

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *