Unable to connect to remote server with SSH-Key

divdax posted 4 years ago


I've setup Laravel 4.1 using the following login credentials in my remote.php:

	'connections' => array(

		'production' => array(
			'host'      => 'xx.xx.xx.xx',
			'username'  => 'deploy',
			'password'  => '',
			'key'       => '/Users/divdax/Sites/app/ssh-key',
			'keyphrase' => '',
			'root'      => '/var/www',


If i run

    Route::get('/', function() {
	    'cd /var/www',
	    'ls -la',

i get this error:

    Unable to connect to remote server.

My host, username and key are 100% valid. Connecting to my server via terminal works fine. The path to my ssh-key is also correct and also the ssh-key file permissions.

return File::get('/Users/divdax/Sites/app/ssh-key');

shows my the content of the keyfile...

Ah, and even if i want to authenticate just with username & password the same error appears. Of course my username & password without a keyfile works fine if i use the terminal.

The machine i connect from is always the same...

What i'm doing wrong? Please help!

milosh012 replied 4 years ago

I also have the same problem...

Pub key is fine, location to the key is fine, I can login from my terminal...

Using PHP 5.4.23.

Not sure what to do anymore...

milosh012 replied 4 years ago

Solved (in my case)... All the time I have using public key as a key parameter. When I changed to use private key, everything works fine!

divdax replied 4 years ago

Not for me. I don't know what i'm doing wrong... Still if only use a working login with username & password without keyfile i get this error.

I also tested this connecting process on a remote server using laravel. I thought it might by a firewall/blocked connection problem.

Stolz replied 4 years ago

I'm having the same problem.

  • No firewall.
  • Read access to key file.
  • Tried both private/public files.
  • Tried both rsa/dsa files.
  • Tried with SSH agent both enabled/disabled.
  • Key file has no password.
  • SSH via command line works well without asking for password.
  • Providing password instead of key file works.
Dombo replied 4 years ago

Hi - sorry to dig up an old thread but I ran into the same problem and found that it remained relatively unsolved.

I dug down into Illuminate/Remote to figure out exactly what was going wrong - the errors aren't very helpful but I don't have the time to make a commit with more descriptive exceptions.

  • Your keyfile must be of type RSA - the implementation for SSH using a keyfile only supports RSA not DSA
  • Your keyfile must not be encrypted (as you rightly highlighted) - openssl rsa –in enc.key -out dec.key
  • As far as I can tell you must provide a literal path, bash shortcuts such as ~ might not work
  • Your must chmod 0600 /dir/yourkeyfile

I'm effectively reiterating what was said elsewhere - but seeing as this is hit #1 in the google lord I figured I'd leave a comment.

qannouf oualid replied 1 year ago

Hello @divdax i'm encountering the same problem you had, please any news about this?

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us