skip to Main Content

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

  • PHP version 7.4.29
  • OS version CentOs Linux 7

ssh2 extention 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?

2

Answers


  1. Have you try to update libssh2?

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search