How to Install OpenSSH Server from Source in Linux

OpenSSH is a free and open source, full implementation of the SSH protocol 2.0. It provides a number of tools for securely accessing and managing remote computer systems, and managing authentications keys, such as...

Spread the love

OpenSSH is a free and open source, full implementation of the SSH protocol 2.0. It provides a number of tools for securely accessing and managing remote computer systems, and managing authentications keys, such as ssh (a secure replacement for tenet), scp, sftp (secure replacement for ftp), ssh-keygen, ssh-copy-id, ssh-add, and more.

Recently OpenSSH 7.9 was released and ships in with many new features and bug fixes; you can read the release notes for more information.

Read Also: How to Install OpenSSH Server from Repositories in Linux

In this article, we will explain how to install and configure the latest version of OpenSSH server and client on a Linux system from sources. We assume that you have an existing installation of OpenSSH suite.

Requirements:

  • A Debian/Ubuntu or RHEL/CentOS Linux system
  • C compiler
  • Zlib 1.1.4 or 1.2.1.2 or greater
  • LibreSSL or OpenSSL >= 1.0.1 < 1.1.0

Install OpenSSH Server and Client in Linux


Before installing latest version of SSH, make sure to check the current version of SSH installed on your system using the following command.

$ ssh -V OpenSSH_7.7p2 Ubuntu-4ubuntu2.5, OpenSSL 1.0.2g 1 Mar 2016

From the above result, the installed OpenSSH version is 7.7, to install latest OpenSSH version, first you need to install few dependencies, i.e development tools or build essentials and the other required packages, as follows.

-------------- CentOS/RHEL 7/6 --------------
$ sudo yum group install 'Development Tools' $ sudo yum install zlib-devel openssl-devel -------------- Fedora 22+ --------------
$ sudo dnf group install 'Development Tools' $ sudo dnf install zlib-devel openssl-devel -------------- Debian/Ubuntu --------------
$ sudo apt update $ sudo apt install build-essential zlib1g-dev libssl-dev 

To create a proper environment for installing OpenSSH version 7.9 server, we need to to create a new system user and group named “sshd”, as well as a safe place to chroot.

Note: Generally, if you have an existing installation, this environment should already be in place, you can skip this section and go to the next. Otherwise, run the following commands to set it up.

$ sudo mkdir /var/lib/sshd
$ sudo chmod -R 700 /var/lib/sshd/
$ sudo chown -R root:sys /var/lib/sshd/
$ sudo useradd -r -U -d /var/lib/sshd/ -c "sshd privsep" -s /bin/false sshd

Explaining the flags in the useradd command above:

  • -r – tells useradd to create a system user
  • -U – instructs it to create a group with the same name and group ID
  • -d – specifies the users directory
  • -c – used to add a comment
  • -s – specifies the user’s shell

Now, download the tarball of OpenSSH version 7.9 from any of the available HTTP mirrors or you can use following wget command to download directly in your terminal.

$ wget -c https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
$ tar -xzf openssh-7.9p1.tar.gz
$ cd openssh-7.9p1/

Now we will build and install OpenSSH server using the --with-md5-passwords, --with-privsep-path and --sysconfdir options, which will install all the files in /usr/local/ (this is the default installation PREFIX).

You can see all available options by running ./configure -h and customize your installation further.

$ ./configure -h

For instance, to enable PAM and SELinux support, add the –with-pam and –with-selinux options, respectively, you need to install all the necessary header files for them to work.

$ ./configure --with-md5-passwords --with-pam --with-selinux --with-privsep-path=/var/lib/sshd/ --sysconfdir=/etc/ssh $ make
$ sudo make install 

Once you have installed OpenSSH, open another terminal windows and check the version of OpenSSH now installed on your system.

$ ssh -V OpenSSH_7.9p1, OpenSSL 1.0.2g 1 Mar 2016

The various OpenSSH configuration files located at:

  • ~/.ssh/* – this directory stores user specific ssh client configurations (ssh aliases) and keys.
  • /etc/ssh/ssh_config – this file contains system wide ssh client configurations.
  • /etc/ssh/sshd_config – contains sshd service configurations.

To configure ssh aliases, see: How to Configure Custom SSH Connections to Simplify Remote Access

You might also like to read these following SSH related articles.

  1. How to Create SSH Tunneling or Port Forwarding in Linux
  2. How to Change Default SSH Port to Custom Port in Linux
  3. 4 Ways to Speed Up SSH Connections in Linux
  4. How to Find All Failed SSH Login Attempts in Linux
  5. How to Disable SSH Root Login in Linux

That’s it! In this article, we’ve explained how to install and configure the latest version of OpenSSH server and client on a Linux system. If you have any questions or comments, use the feedback form below to reach us.

Facebook Comments
Spread the love

Posted by News Monkey