Force Password Authentication with SSH

If you want to connect to a host by using a password instead of a public key you can use the following command to initiate a request.

Note: This will only work if your host allows the user you are trying to connect with to authenticate by using password. Typically, this is disabled for root users and not advised to enable password authencation unless you really know what you are doing.

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no

Adding SSH2 to MAMP and MAMP PRO on Yosemite the easy way


You will require autoconf.

Install via the above instructions will work. Also, using Homebrew will work.

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

Download the php version that matches the one you will be using with MAMP Pro.

Copy the extracted files to MAMP php folder in /Applications/MAMP/bin/php/php5.5.18/include/php

Do not copy the subfolder created by the extraction, only copy the contents of that folder. You may have to create the ‘include/php/‘ folders as they might not already exist.

Also, do change the PHP version number to match the one you’re using.

./configure --without-iconv

Adding SSH2 extension to your MAMP the sure way

  1. Download libssh2 from source forge, direct link here
  2. Then extract the package, configure, compile and install it.
    user:compile$ tar -xf libssh2-1.2.1.tar
    user:compile$ cd libssh2-1.2.1
    user:libssh2-1.2.1$ ./configure
    user:libssh2-1.2.1$ make
    user:libssh2-1.2.1$ sudo make install
  3. Download SSH2 PECL source code, get the latest stable version.
  4. Then untar and compile it.
    user:compile$ tar -xf ssh2-0.12.0.tar
    user:compile$ cd ssh2-0.12.0
    user:ssh2-0.12.0$ phpize
    If you don’t have have autoconf installed this is where you will get an error. Cannot find autoconf. Otherwise, proceed.
    user:ssh2-0.11.0$ ./configure
    If you get this error

    /Applications/MAMP/bin/php/php5.5.18/include/php/Zend/zend.h:51:11: fatal error: ‘zend_config.h’

          file not found

    This is probably because you did not compile the PHP you downloaded.
    user:ssh2-0.11.0$ make
  5. Look in
    ssh2-0.12.0/modules/ to find
    Copy this file to your MAMP location.
  6. Chmod 755 the location of your file.
  7. Edit templates in MAMP Pro, File->Edit Template->PHP-> Choose the PHP version you have compiled with.
  8. Add the line , in the [extensions] section
  9. Save changes
  10. Restart MAMP Pro
  11. Check phpinfo()
  12. Try it out

2015 03 01 11 47 08 PM 

If you are using Linux, such as Debian, Ubuntu you can install XAMPP for Linux. Compile ssh2 using the same instructions, update the php.ini file the same way. 




Add to MAMP pro from source

A tell tale sign that ssh2 is missing is that exception is thrown on the line using this function.

ssh2_connect( ) ;



Adding SSH2 extension to your MAMP the hard(er) way

Well, if my binary above doesn’t work for you, then you may have to compile SSH2 extension yourself. Please look over my other article Rebuilding MAMP stack from scratch. to make sure you have all the prerequisites. Assuming that you do,

  1. Download libssh2 from sourceforge.
  2. Then untar the file and compile it.
    user:compile$ tar -xf libssh2-1.2.1.tar
    user:compile$ cd libssh2-1.2.1
    user:libssh2-1.2.1$ ./configure
    user:libssh2-1.2.1$ make
    user:libssh2-1.2.1$ sudo make install
  3. Download SSH2 PECL source code.
  4. Then untar and compile it.
    user:compile$ tar -xf ssh2-0.11.0.tar
    user:compile$ cd ssh2-0.11.0
    user:ssh2-0.11.0$ phpize
    user:ssh2-0.11.0$ ./configure
    user:ssh2-0.11.0$ make
  5. Once you successfully compile, you should have under modules/ directory. At this point, you can simply copy the file to the appropriate location of your PHP (or you can follow the same instructions above for either MAMP or the built-in PHP).

That’s about it … I hope that this article helps you in enabling ssh2 extension for PHP on your MacOS X. And as always, I welcome comments / suggestions / questions. I’m looking forward to improving my solution with your comments / suggestions / questions.

Install SSH2 with MAMP Pro 5.5.10+

I ran into the issue with php.h missing.


The path for this system is set with


export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:

export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.10/bin


This ensures PHP from MAMP Pro is being used not the OSX version. 

 When trying to compile SSH2 php.h is missing which causes fatal error…. 

 Follow these steps, and retry SSH2 compilation as per these steps.


Here’s how I fixed it:

  1. MAMP doesn’t provide the source code archive for PHP 5.4.10 so download it from
  2. Extract the source code archive to /Applications/MAMP/bin/php/php5.4.10/include/php
  3. Run ./configure to configure the source code for your platform (without this step the pecl install will fail looking for a bunch of header files)
  4. Retry compilation for ssh2


If you run phpinfo() you should now get an entry for ssh2 as follows:


SSH2 support enabled
extension version 0.12
libssh2 version 1.4.3
banner SSH-2.0-libssh2_1.4.3 


Additional reading:

Install SSH2 on OSX MAMP PRO



Updated instructions 2014

brew update

brew doctor

brew install libssh2
cd /Applications/MAMP/bin/php/php5.4.25/
sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade
sudo pecl install channel://

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :

Build process completed successfully

Installing ‘/usr/lib/php/extensions/no-debug-non-zts-20100525/’

install ok: channel://

configuration option “php_ini” is not set to php.ini location

You should add “” to php.ini


cp /usr/lib/php/extensions/no-debug-non-zts-20100525/ /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/

chmod 755 /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/

Edit template, add

restart apache, check for ssh2 with phpinfo mama start page

which php should give you the version of php on osx, if the one you’re using with mamp is not far apart then this method will work, otherwise you will have to compile with php version that matches the one you’re using in mamp


How to install for PHP 5.3.x on OSX Lion and MAMP


For a recent project I needed to use the ssh2 extension with PHP. I had tried to use phpseclib, but found that it doesn’t support for DSA keys (a requirement for my project). Using the instructions below, you can easily install ssh2 support for PHP using homebrew.

Using homebrew to install libssh2:

brew install libssh2

I was working with a fresh OSX Lion install, so I needed to install pear. Luckily it comes with Lion, so we just need to install and update.

sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade

After pear is setup, we can use pecl to install the ssh2 extension:

sudo pecl install channel://

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :

This next step is optional and should not be done if you already have a /private/etc/php.ini file. However, this step may help others who are working with a fresh install like I was:

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Now we need to add the to the php.ini …so open /private/etc/php.ini with your favorite editor and add the following line:

After saving, run the following command and it should output ‘ssh2′:

php -m | grep ssh2

Now lets copy to the MAMP extension folder:

cp /usr/lib/php/extensions/no-debug-non-zts-20090626/ /Applications/MAMP//bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/

Edit the php.ini template for MAMP’s PHP install and add:

MAMP PHP Template

Restart MAMP… ssh2 extension should now be installed for the system’s PHP and MAMP’s PHP.

Output of phpinfo(); will show this: