Solved

SSH to Linux from windows in Perl

Posted on 2009-05-10
4
1,615 Views
Last Modified: 2012-05-06
I need to SSH to a linux box, from a windows box, and run some interactive commands to do an installation. And I have to user perl to accomplish this.

So I have run a perl script on a windows box, that will then ssh to the linux box and run commands one after the other interactively... I will have to answer in yes/no or select from 1,2,3 etc.

Is there a way to do this? I am not sure if I have provided enough information but I can answer any questions if someone has suggestions.

Thanks.
0
Comment
Question by:pavanbh
4 Comments
 
LVL 28

Accepted Solution

by:
FishMonger earned 168 total points
ID: 24348751
0
 
LVL 8

Assisted Solution

by:thetmanvn
thetmanvn earned 166 total points
ID: 24348892
Very details example using perl ssh to execute shell remotely via ssh

http://www.example-code.com/perl/ssh_exec.asp

More sample code:
http://www.example-code.com/perl/ssh_remote_command.asp
http://www.example-code.com/perl/ssh_tunnel.asp

Hope this help
0
 
LVL 2

Assisted Solution

by:jccs0519
jccs0519 earned 166 total points
ID: 24357365
If you just need Perl example or module the other comments should work for you.

If you're looking for an environment to do this on a Windows box, then you'll need to install Cygwin, there might be other solution but Cygwin works for me.  I did the same thing before using this app.

Cygwin is basically a bunch of Unix utilities that'll work on Windows command prompt.  Once installed, it'll popup like a Windows command prompt, except you can use a lot of unix utilities like ls, ssh/scp, bash scripts.  When you install you can choose what package or utilities you want to include.  I've even ran X-windows on top of Cygwin where I can remotely export X-Windows tools from a remote server like Sun Solaris admin tools.  I also has setup perl scripts to access mysql DB using cygwin before.

Anyway, in  your case, you'll need perl and ssh package.  Once install, setup ssh keys where you can access linux server without password.  ssh-keygen -t rsa, copy key to linux .ssh/authorized_keys, ensure 755 in user login, but 600 in .ssh directory.  Then you can write your perl or shell script to access the linux server.  You can remotely exec commands via ssh (ie. $ ssh linuxbox ls -l).

Hope that helps
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 86
canBalance challenge 34 70
My project did see openJDK that I installed. What could be the problem 7 123
SQL400 max size 5 78
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now