The Crumpet has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Problem with Apache and SSH: Help needed!

Replies are listed 'Best First'.
Re: Problem with Apache and SSH: Help needed!
by tachyon (Chancellor) on Apr 08, 2002 at 07:39 UTC

    we a running into problems

    Uh huh. Any further hints other than it does not work! Code perhaps. The error message(s) even. You seem to expect us to have ESP. Using my ESP I would suggest that if a Perl script has a problem running a working command line client it likely relates to permissions, not perl.

    A perl interface to SSH is Net::SSH::Perl

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Problem with Apache and SSH: Help needed!
by jeffenstein (Hermit) on Apr 08, 2002 at 08:05 UTC

    Not a lot of information to go on, but I'll give it a shot anyway.

    My guess is that the account that the cgi script runs as is different than the account you are using on the command line, and is not authorized to connect to the remote hosts.

    Another possible problem is if you are using the ssh-agent for authentication, as the cgi script will not pick up the required environment variables.

    Also, if you are using ssh to access new hosts, it will need a tty to ask for confirmation about new host keys. This could be combined with the first problem. If the web server account has never used ssh to access the other hosts, the first time it accesses each host it will need a tty to ask for confirmation about the host key, even if you have successfully used ssh from another account (including root) on the same server to access the other host.

      Hi, Sorry if I didn't give too much information. I guess being my first time here, I didn't want to post a very long message. Anyway, you are right in that, it might be a problem of permissions. However, I set my directory permissions to 777. I still feel it is just a matter of permissions.
      I have the executable that I want to run sitting in /home/<user>/Scatter/bin and the permissions are 777 on this.
      For starters, any idea how apache/httpd runs or executes other scripts?
      I tried running "system("ls")" from the script and it gave me the results. However, when I tried
      system("ssh <machine name> pwd")
      the bally thing just hung! I have ssh set up so that I can ssh from the head to the nodes without using the passwords (basically I generated the keys using keygen and then copied them onto the authorization keys).
      Also, when I checked the error logs, it just gave an "Aborted by User" error.
      Hope I have been a little clearer with the problem.

        Have a look at perlman:perlfunc on what system() actually does ie a fork() exec(). The script probably hangs because ssh is waiting for user input. Try executing via backtics and printing the output from ssh.

        print `ssh [blah]`;

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        For starters, any idea how apache/httpd runs or executes other scripts?

        You'll need to look at the http.conf to see what the username and group name are for the web server. ps -ef or ps -aux should also shed some light on the subject.

        Once you have this information, then you can su to this user and try ssh <somehost> pwd to see what it says, as this is closer to how the perl script would run it under cgi. It would actually run as this user without a tty, but that is harder to simulate.

        If you've generated keys as your userid, you may need to use ssh user@host to ssh to a different account. man ssh would have information on how to do this. Most likely, you'll also need to copy the private keys to the web server account.

        Last, mode 777 is evil!. The directories/scripts should be mode 755, as write permission is not needed to run the scripts. Leaving them mode 777 allows anybody with access to that box to change your scripts and files (either maliciously or accidentally).

        And, of course, read all the documentation you can find on apache and ssh. Hope this helps you on your way.

(smitz)Re: Problem with Apache and SSH: Help needed!
by smitz (Chaplain) on Apr 08, 2002 at 11:04 UTC
    Hey Crumpet,
    I had a similair problem once, trying to run ssh in a CGI. I think my problem was that although it ran fine from the command line, (as user smitz), when run under CGI (user nobody) ssh didnt have a host/allow file, so it asks

    'Accept this key? %^&5675%^& etc...'

    I solved it (stupidly!) by getting the admin to log in as nobody and ssh to my server just once, then press 'y' when it asks to accept the key. Then it worked.
    I say stupidly because, of course, I should have used Net::SSH::Perl. As should you!


    SMiTZ
Re: Problem with Apache and SSH: Help needed!
by mattr (Curate) on Apr 08, 2002 at 09:42 UTC
    Um, dunno, how about these questions.

    Is ssh in the path of the user the web server runs as (webrun, nobody.nogroup, etc)? Try putting it in /bin..

    Is the web server user registered in .ssh?

    What is your ssh site config file like?

    Maybe your configs do not allow some users to do things they need to do like ssh, icmp, etc?

    Are you sure it is hanging, or that it worked not once? (ssh "needs" to hang a little on close, see openssh.org). Sounds like this isn't the problem though..

    Does the Net::SSH wrapper for the binary also fail??

Re: Problem with Apache and SSH: Help needed!
by rbc (Curate) on Apr 08, 2002 at 21:23 UTC
    My guess is that ssh is expecting to recieve user and password
    from stdin. You may need to configure you ssh to not prompt
    for a user /password. I forget how to do that. Try man ssh