Jump to content

Recommended Posts

HI folks

 

Has anyone successfully used PHP with authorized keys to access another server?

 

I'm playing with the idea of writing a control panel for a Linux app. I don't want to keep the root passwords in a database so authorized keys looks like a good way forward. However I can't seem to get test code to work :(

 

<?php

$test = shell_exec('ssh root@myserver; uname -a');

echo "<pre>$test</pre>";
?>

 

Running this *should* IMHO give me the output of uname -a on 'myserver'. It doesn't. It gives me the output of uname -a on my laptop! However running exactly the same command in my laptops terminal window gives me the correct response i.e. uname -a on myserver.

 

Any ideas?

 

Huw

Link to comment
https://forums.phpfreaks.com/topic/166966-php-and-authorized-keys/
Share on other sites

Yes, I am sure:

 

daniel@daniel0:~$ hostname
daniel0.net
daniel@daniel0:~$ ssh phpfreaks.com 'hostname'
phpfreaks.serverpowered.com

 

Are you sure you've got the keys properly setup? Note that it will try with the private key for the user that PHP is run as (which means the user the web server is run as if you run it through a web server). You might want to explicitly set the identity file when calling ssh.

Note that it will try with the private key for the user that PHP is run as (which means the user the web server is run as if you run it through a web server). You might want to explicitly set the identity file when calling ssh.

 

That sounds about right. How can I explicitly set the identity file?

 

Thanks for your help. This is very useful :)

In your case, only the user huw would have access to that .ssh directory. Either make a new key for Apache/PHP or move the key to where it is writable.

 

I wouldn't recommend using the root user though. You should use an unprivileged user unless the command you wish to run absolutely needs root.

In your case, only the user huw would have access to that .ssh directory. Either make a new key for Apache/PHP or move the key to where it is writable.

I'll try this tomorrow.

 

 

I wouldn't recommend using the root user though. You should use an unprivileged user unless the command you wish to run absolutely needs root.

Yes. I'm thinking of writing some code to manage some server processes that run as root. The good new though is that the machines are not accessible from the net. Even so I'm putting security at the top of the agenda. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.