Mahesh
Mahesh

Reputation: 21

ssh2_connect(): error starting up ssh connection(-5): unable to exchange encryption keys + centos 7 + php7.4

While connect my destination server by

ssh2_connect("<<server-ip>>", 22)

then received error:

ssh2_connect(): error starting up ssh connection(-5): unable to exchange encryption keys

ssh2 extension and lib2ssh 1.8.0 already installed.

enter image description here

How to resolve this issue? Does any library need to be added or updated?

Upvotes: 2

Views: 615

Answers (1)

Eshban Bahadur
Eshban Bahadur

Reputation: 1018

This problem is common when the versions are outdated or don't have matching encryption settings.

  1. You need to update your libssh2. The newer version will add support for additional key exchange algorithms and improved compatibility with modern SSH servers.

First remove the old version of libssh2 from this command:

sudo yum remove libssh2

Then, download and install the latest version:

wget https://www.libssh2.org/download/libssh2-1.10.0.tar.gz
tar -xvzf libssh2-1.10.0.tar.gz
cd libssh2-1.10.0
./configure
make
sudo make install

After installation, verify the version of libssh2

libssh2 -V
  1. Now you have to rebuild the PHP ssh2 extension to ensure it links correctly to the newer version. So first you have to install the development dependencies:
sudo yum install php-devel

Now, uninstall and reinstall the PHP ssh2 extension

pecl uninstall ssh2
pecl install ssh2

Restart your webserver( no sure which webserver you are using)

sudo systemctl restart httpd   # For Apache
sudo systemctl restart php-fpm # For Nginx with PHP-FPM

If this update cannot fix your issue you have to update the key exchange algorithms on the server. So update me and I will help you out.

Upvotes: 2

Related Questions