Not able to ssh to other server from CGI script


 
Thread Tools Search this Thread
Top Forums Programming Not able to ssh to other server from CGI script
# 1  
Old 02-24-2012
Not able to ssh to other server from CGI script

Hi All,

I have designed a web tool in perl cgi in UNIX Solaris 10 platform.

According to my cgi script (in server A) it should execute a script (in server B) using ssh key authentication, but it is not.

And when I am trying to execute the command without cgi script, the script in server B is executing.

I am using following command

/usr/bin/ssh -i mykey -l <login_id> <hostname> /<path>/connection.sh

Can anyone help me on this? and tell me if I am missing any special configuration to be done to execute the script through CGI?
# 2  
Old 02-24-2012
The cgi script almost certainly isn't running under the same user as you login as, but the user ID of the web server, which will prevent it from reading the key files.

You'll need to keep key files owned by the web server in a directory owned by the web server, with similar permissions to your own ~/.ssh and things inside it.
# 3  
Old 02-28-2012
Hi Corona,

Thanks for the input...

As you said the owner of the web server is different from the owner of the key.
But I have given 777 permissions to the my private, in this case any user should be able to access the key....but still the problem persist.

Is there any other troubleshooting step we can perform to resolve this.

Thanks,
Ankit.
# 4  
Old 02-28-2012
Quote:
Originally Posted by ankit_talwar
But I have given 777 permissions to the my private, in this case any user should be able to access the key...
No no no. 777 is not the magic sledgehammer to fix all permissions problems. These numbers mean things and have farther consequences than you might think. Do you really want your private key to be read by everyone on the system!?

ssh in fact knows that 777 is ridiculous and stupid, and will refuse to use a key in a folder with 777 permissions.

It should be 700, and owned by the same user as your web server.

The private key should be 600.

The public key should be 644.
# 5  
Old 02-29-2012
Yeah..that's true...I changed the permissions just to check if the key is accessible....well I will create a key owned by the owner running the webserver and see if the problem solves.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash scripts - CGI and ssh

Hi Everyone, I started looking at the possibility of making some of our bash scripts available through a web server using CGI and the simple ones works just fine. Now I need to execute remote commands using ssh but can't really get it to work. I got private keys all sorted. Must be ssh... (1 Reply)
Discussion started by: arizah
1 Replies

2. UNIX for Advanced & Expert Users

CGI script using ssh

Hi Friends, I am using a cgi script which calls a shell script internally. Now, I want to change it with ssh (without password). Can you please help? Code:cat maininfo.cgi #!/usr/bin/perl -w use Net::Telnet (); use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser... (1 Reply)
Discussion started by: suresh3566
1 Replies

3. Shell Programming and Scripting

Script to ssh to remote server

Hi All, I need to prepare a script. Description: Currently i am in server "x(ubuntu os)", here i need to develop a script to ssh to another server "y(ubuntu os)", i have password less authentication to "y". i have done the below #!/bin/bash #ssh to the server "y" and confirming i am... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

4. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

5. Shell Programming and Scripting

Script to SSH into a server

Hi, Actually i'm trying to write a script which needs to ssh into a server and run a command on the server, after entering a valid login. But after ssh the script will no longer run on the SSHed server :( so is there any way to do so ??? (1 Reply)
Discussion started by: nagios
1 Replies

6. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

7. Shell Programming and Scripting

How to pass data from server (CGI script) to client (html page)

Hi I know how to pass data from client side (html file) to server using CGI script (POST method). I also know how to re-create the html page from server side after receiving the data (using printf). However I want to write static pages on client side (only the structure), and only to pass... (0 Replies)
Discussion started by: naamabm
0 Replies

8. Shell Programming and Scripting

How to execute remote ssh command - Perl and CGI

Hi, I am having nightmare issue-ing remote ssh command from a CGI perl script. It just won't run on debug message: It says permission denied. Can I even do this? as the apache server running under DAEMON account probably can't execute it? Is this the case of what's going on? Here is my... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

9. Shell Programming and Scripting

Automated script to SSH to another server

Hi guys, I have a script which looks a little like this; grep $id /usr/local/production/service/distributor/clients/*/out/events.xml | awk -F/ '{print $8}' I want to be able to run this on my dev box, so need to add something into the script which will SSH onto the live server, collect the... (2 Replies)
Discussion started by: JayC89
2 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question