Visit Our UNIX and Linux User Community

CGI script using ssh

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users CGI script using ssh
# 1  
Old 07-19-2016
Debian 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?

cat maininfo.cgi

#!/usr/bin/perl -w 
use Net::Telnet ();
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my $name = param('getvalue');
$t = new Net::Telnet(Timeout=>20,Prompt=>"/.*>/");
my $subinfo=$t->cmd("/bin/ $name");
print qq~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">
<title> Info Search</title>
<head><title>Info Search</title></head>
<body bgcolor=white background="Graphic_sample52679.jpg" lang=EN-US style='tab-interval:.5in'>
<center><b><font color="darkblue">**********Information Searching**********</font></b></center>
<center><b><font color="darkblue">Key           : $name</font></b>

<BODY background="background_main.jpg">
<body bgcolor=darkslategray lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>

<font color=darkblue>
<pre> @clid </pre>

Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes it far easier to read and preserves spaces for indenting or fixed width data.

Last edited by rbatte1; 07-19-2016 at 10:09 AM.. Reason: Added CODE tags and moderator comment.
# 2  
Old 07-19-2016
If you arrange proper ssh keys for noninteractive logins, your program becomes as simple as:

my $subinfo=`/usr/sbin/ssh -i /path/to/identityfile username@ /bin/ $name`;


You use keys like this, with minor differences -- the -i is because your CGI script isn't an interactive login and likely has no home folder to find ~/.ssh/ in. You'll have to pick your own place to put it -- preferably someplace apache itself refuses to touch (which won't stop your perl script or ssh from getting it).

The identity file itself should belong to apache:apache (or whatever user/group your webserver uses) and be set 0400. The folder should also belong to your webhost user/group and be set 0700.

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. Shell Programming and Scripting

Help need in CGI script

Hello All, first of all please forgive me if I have brocken some rule of this forum and this is not a homework :). Could you please help me as I have created a new apache service in a server by creating a new httpd.conf for the new service. Now in the httpd.conf file I have studied by... (3 Replies)
Discussion started by: RavinderSingh13
3 Replies

3. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/ -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Programming

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... (4 Replies)
Discussion started by: ankit_talwar
4 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 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

Perl cgi script to call bash script?

Novice to perl here. I have created a simple web page in perl, with only one submit button. I would like to execute a bash script on the same server when this button is clicked on. Is this possible in perl? I have spent a few days researching this and am unable to find any useful information.... (0 Replies)
Discussion started by: pleonard
0 Replies

8. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./ $t $d $m'); in shell scipt i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

9. 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

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

Featured Tech Videos