• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • Forums
  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » Linux & Servers » Install SSH2 For PHP Shell Connections

Install SSH2 For PHP Shell Connections

Last updated on February 13th, 2019 at 10:01 am by Ehi Kioya 2 Comments

A general overview of SSH2 for PHP can be found at the official Secure Shell2 reference. If you look at the requirements section, you will see that two other libraries are required for it to work. They are OpenSSL and libssh2. I explain here how to install both of these first. And then we proceed to actually install ssh2 for PHP shell connections.

Installing OpenSSL

Run any of the following commands to determine if OpenSSL is already installed on your machine:

Debian

1
dpkg -l | grep -i openssl

RPM

1
rpm -qa | grep -i openssl

If the output includes a line like this (version numbers might differ), you already have OpenSSL installed. You may proceed to Installing libssh2.

1
ii  openssl                                1.0.1-4ubuntu5.9                        Secure Socket Layer (SSL) binary and related cryptographic tools

Depending on your screen width, you may have to scroll to see the full text of the above line.
(It was copied directly from the terminal with no formatting changes).
If OpenSSL is not installed, use any of the following commands to install it:

Debian based machine

1
apt-get install openssl

RedHat based machine

1
yum install openssl

Installing libssh2


Create a temporary directory to download the source files to and then cd to the newly created temporary directory.
The whole process is completed with the following commands:

wget http://sourceforge.net/projects/libssh2/files/old-libssh2-releases/1.1/libssh2-1.1.tar.gz
tar -zxvf libssh2-1.1.tar.gz
cd libssh2-1.1
./configure
make
make install

Once these steps have been successfully completed delete the previously created directory.
 

Install SSH2

Download the ssh2 package (check the latest version here):

1
wget http://pecl.php.net/get/ssh2-0.12.tgz

Create a build directory and untar the package:

mkdir build-dir
mv ssh2-0.12.tgz build-dir
cd build-dir
tar xzvf ssh2-0.12.tgz

Prepare the compile step and compile:

phpize
./configure --with-ssh2
make
make install

Copy the module in the system (For 32 bit machine):

1
cp modules/ssh2.so /usr/lib/php/modules/ssh2.so

Copy the module in the system (For 64 bit machine):

1
cp modules/ssh2.so /usr/lib64/php/modules/ssh2.so

 
Confirm that this file
/etc/php.d/ssh2.ini
includes this line:

1
extension=ssh2.so

 
You may now delete the build directory:

1
2
cd ../../
rm -f build-dir

Restart Apache
(Debian based machine):

1
/etc/init.d/apache2 restart

Restart Apache
(RedHat based machine):

1
/etc/init.d/httpd restart

Now make sure that ssh2.so is really loaded by executing the following command:

1
php -i | grep ssh2

You should see something like this:

/etc/php5/cli/conf.d/ssh2.ini,
Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp
ssh2
libssh2 version => 1.2.6
banner => SSH-2.0-libssh2_1.2.6

 

*UPDATE:

I found a quicker method for installing ssh2. After installing (or confirming that you already have) openssl, just run the following commands to get ssh2 up and running:

1
2
3
sudo apt-get install libssh2-1-dev libssh2-php
sudo php5enmod ssh2
sudo service apache2 restart

I have tested this on Ubuntu 14.04 LTS.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: Linux & Servers, Programming Tagged With: Security, Ubuntu

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Comments

  1. clakoman says

    September 4, 2013 at 9:02 am

    Meh – I prefer phpseclib, a pure PHP SSH implementation:

    http://phpseclib.sourceforge.net/

    It offers a number of advantages over the libssh2 solution you’re proposing:

    http://stackoverflow.com/a/14305875/569976

    Also, although some apps might have built-in libssh2 support, there may well be phpseclib plugins for those apps. eg.

    http://wordpress.org/plugins/ssh-sftp-updater-support/

    Reply
    • Ehi Kioya says

      September 4, 2013 at 9:20 am

      This is useful information clakoman.
      The plugin seems like a nice hassle free method.
      I’ll definitely have a look. Thanks.

      Reply

Leave a Reply Cancel reply

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

Primary Sidebar

26,221
Followers
Follow
30,000
Connections
Connect
14,641
Page Fans
Like

POPULAR   FORUM   TOPICS

  • How to find the title of a song without knowing the lyrics
  • Welcome Message
  • How To Change Or Remove The WordPress Login Error Message
  • The Art of Exploratory Data Analysis (Part 1)
  • Replacing The Default SQLite Database With PostgreSQL In Django
  • Getting Started with SQL: A Beginners Guide to Databases
  • How To Create Tooltips Using CSS3
  • How To Use A Custom Bootstrap Template With Laravel
  • SEO Basics – Crawling, Indexing And Ranking
  • How To Stay Relevant In The Tech Space
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library
    This article explains how to bypass the single user remote desktop connection restriction on Windows 10 by using the RDP wrapper library.
  • WordPress Password Hash Generator WordPress Password Hash Generator
    With this WordPress Password Hash Generator, you can convert a password to its hash, and then set a new password directly in the database.
  • Forums
  • About
  • Contact

© 2021   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy