简体   繁体   中英

Unable to ssh to a remote machine through shell script while accessing it from UI

I have a Linux machine where I have created a cgi script (JarPatch.cgi), the code of which looks like this:

#!/usr/bin/perl
use warnings;
print "Content-type: text/html\n\n";
system ("sh JarPatch.sh");

The code of JarPatch.sh looks like this:

#!/bin/bash

echo "Inside jar patching tool";

PJS_DEV=app4915@slcai833.us.oracle.com;
ssh -f $PJS_DEV  "cd /slot/ems4915/appmgr/tmp; echo stopping server ;  ./find_stop_servers.sh;"

   echo "Exit jar patching tool";

This script will basically shut down a server running on the remote machine

Problem statement is this: When I execute this cgi script through Linux terminal. I can see that the ssh commands are getting executed. Server is shut down.

When I access the cgi script through a windows machine in a browser, the shell script is invoked but ssh seems not to be working.

Can any one give me a pointer to resolve this issue please? I am new to perl/shell integration. So might be missing something small as well. Thanks

When you ssh from windows machine all connections are made as webuser which is not authorized to ssh into remote machine. On other hand when you ssh from linux terminal you are able to ssh as user there is authorized to do so. This is because linux user has its ssh key on remote server.

You can also try to look into ProxyCommand which might come to rescue but i have no idea how it will work with windows.

Other approach is to create ssh keys for webuser and put them into remomte server which will be security risk.

When you run it as yourself ssh is offering your keys to authenticate you. When you run it through the webserver, the webserver user is trying to run the ssh command, and does not have your ssh keys to offer, so is probably being prompted for a password, and not successfully logging in.

You could fix this by generating ssh keys for the webserver user and sharing that key with the target system as well, which has some security implications to say the least.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM