Use source code to upgrade OpenSSH_7.6p1 to OpenSSH_9.3p1 on ubuntu 18.04

1. Check the current SSH version installed on the system

Use the command ssh -Vto view the current ssh version, the output is as follows:

OpenSSH_7.6p1 Ubuntu-4ubuntu0.7, OpenSSL 1.0.2n  7 Dec 2017

2. To install dependencies, execute the following commands in sequence

sudo apt update
sudo apt install build-essential zlib1g-dev libssl-dev

3. Set up the environment

In order to create a suitable environment to install the OpenSSH service, an installation environment needs to be created

sudo mkdir /var/lib/sshd
sudo chmod -R 700 /var/lib/sshd/
sudo chown -R root:sys /var/lib/sshd/

4. Download the source code and install it

Download OpenSSH version 9.3 from any available HTTP mirror , or wgetdirectly in the terminal using the command

Download the source code to any folder:
wget -c https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz

Unzip:
tar -xzf openssh-9.3p1.tar.gz

Enter the source code folder path:
cd openssh-9.3p1/

PAMIf you want to enable and support when installing , you need to add and options SELinuxrespectively , and you need to install all the necessary header files for them to work properly.--with-pam--with-selinux

Installation dependencies:
sudo apt install libpam0g-dev libselinux1-dev libkrb5-dev

To install ssh, execute the following three commands in sequence:

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

After the installation is complete, restart the system, otherwise the remote connection will continue to use the old version

5. Check for new versions

view locally

Open a new terminal and run:
ssh -V
insert image description here

remote viewing

Check if the OpenSSH version has changed on the remote machine:

ssh -v user@ip

Find the line in the output information Remote protocol version. If the old version number is displayed,
insert image description hereyou need to copy the new version. The operation is as follows:

cd /usr/sbin
mv sshd sshd.bak    # 备份旧版本的sshd
sudo cp /usr/local/sbin/sshd sshd     # 复制新版本sshd

Use the remote view version command again (to be on the safe side, it is recommended to restart after copying):

ssh -v [email protected]

insert image description hereThe version has been updated to 9.3

The various OpenSSH configuration files are located at:

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

6. Remote connection

ssh <user>@<ip>
insert image description here

Guess you like

Origin blog.csdn.net/ylfmsn/article/details/132273884