Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-23-2008, 01:59 PM   #1
LQ Newbie
Registered: Mar 2004
Location: Bloomington, IN
Posts: 21

Rep: Reputation: 15
Using SSH Public Key Authentication with PHP

I'm developing a website with PHP where I want the web server to pass information via SSH to a separate jobs server to process.

Now I'm pretty sure what I want here is to use public keys so that the servers can talk without needing to password authenticate every time.

What I'm having a hard time figuring out is how to generate the SSH keys initially. The PHP pages are executed by a non-login user, wwwrun, which also obviously doesn't have a .ssh directory to store the key in.

What is the best way for me to do this? Do I need to use a bunch of exec() statements to create the key and pass it a blank passphrase when it asks for one? Where can I store it?

The web server does not have the PECL SSH2 extension installed, if that makes a difference.

Thanks for any help.
Old 05-24-2008, 02:47 PM   #2
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
Have you considered (and rejected) using cURL to access a remote server using HTTPS? It would mean putting a script on that server to do what is needed, but then you could be assured of all the right stuff happening with certificates without any involvement by your application code.
Old 06-17-2008, 11:37 AM   #3
LQ Newbie
Registered: Mar 2004
Location: Bloomington, IN
Posts: 21

Original Poster
Rep: Reputation: 15
Just for future reference for anyone else with this issue, here's what I wound up doing:

First of all, I created the key for the user wwwrun by editing /etc/passwd and changing the default shell for the user from /bin/false to /bin/bash. That allowed me to use 'su wwwrun' to log in as the wwwrun user. Using 'cd ; pwd' I found that wwwrun actually does have a home directory inside the filesystem, so that's where I used ssh-keygen to create the key pair and copied the public key to the remote server.

I made sure to edit /etc/passwd to change wwwrun's shell back to /bin/false, and now no-login scp is working just fine.

Thank you guys for your help.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh public key authentication teacup Linux - Networking 4 11-28-2011 12:27 AM
Public key authentication with ssh elnacho12 Linux - Networking 3 12-18-2007 09:38 AM
Public Key Authentication with SSH edafe Ubuntu 1 08-26-2006 12:06 PM
ssh public key authentication setup mikewgilligan Linux - Security 7 07-12-2006 09:54 PM
Can't use public key authentication with SSH Noob69 Linux - General 5 01-06-2006 07:27 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration