470,874 Members | 1,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

ssh with shell_exec

Hi,

I'm trying to 'ssh' into another machine, run a small script and fetch
it's output, using shell_exec(). The problem is, it takes AGES to run
ssh and I don't know what's happening. If I try 'ssh'ing manually on the
shell, it takes a microsecond to fetch the result, whereas shell_exec
takes very very long and I don't know how to debug the problem. That's
problem number one: How do I tell what's happening and why is it taking
so long?

Problem two: To be able to establish a password-less ssh connection, I
generated a public key/private key pair for the two machines and stored
it in my /home/username/.ssh directory. Okay, I know apache/php (by the
way I'm running apache with PHP 4.2.3) won't know where to find it so I
presumed /opt/apache/.ssh would be the best place to copy the ".ssh"
directory (i.e. apache's installed in /opt/apache). Now the problem is,
I couldn't get shell_exec to run ssh in a password less mode. After a
little while I realized that it was looking for the private key in
"/.ssh" (i.e. the root directory)! How come? How do I change it so that
it looks for the .ssh directory elsewhere? (I mean, how can I run a
command using shell_exec and ask it to use the "home" directory of the
"apache" user, which normally is /path/to/apache)? The last time I
installed php & apache, I remember it looked for the .ssh directory in
the /opt/apache/.ssh directory and now it has changed. also, it was much
faster the last time. Now for some reason it's EXTREMELY slow (takes a
whole minute to run ssh) and looks for the .ssh directory on the root
(and I dont want to place that directory there).

PLEASE HELP! Any suggestions would be great! Thanks,
Steve

Jul 17 '05 #1
1 5517
Steve <nospam@nopes> writes:
Problem two: To be able to establish a password-less ssh connection,
I generated a public key/private key pair for the two machines and
stored it in my /home/username/.ssh directory. [...] After a little
while I realized that it was looking for the private key in "/.ssh"
(i.e. the root directory)! How come? How do I change it so that it
looks for the .ssh directory elsewhere?


I think you should look at the -i switch to ssh, from the ssh man
page:

-i identity_file
Selects a file from which the identity (private key) for RSA or
DSA authentication is read. The default is $HOME/.ssh/identity
for protocol version 1, and $HOME/.ssh/id_rsa and
$HOME/.ssh/id_dsa for protocol version 2. Identity files may
also be specified on a per-host basis in the configuration file.
It is possible to have multiple -i options (and multiple identi-
ties specified in configuration files).
--
Martin Geisler My GnuPG Key: 0xF7F6B57B

See http://gimpster.com/ and http://phpweather.net/ for:
PHP Weather: Shows the current weather on your webpage and
PHP Shell: A telnet-connection (almost :-) in a PHP page.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sandman | last post: by
8 posts views Thread by Good Man | last post: by
6 posts views Thread by jonathan.beckett | last post: by
reply views Thread by Don | last post: by
3 posts views Thread by Paul F. Johnson | last post: by
reply views Thread by Akkad | last post: by
3 posts views Thread by Lawrence Krubner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.