ssh with shell_exec

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    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

  • Martin Geisler

    #2
    Re: ssh with shell_exec

    Steve <nospam@nopes > writes:
    [color=blue]
    > 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?[/color]

    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.

    Comment

    Working...