LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2007, 04:18 AM   #1
wanna13e
Member
 
Registered: Apr 2006
Posts: 45

Rep: Reputation: 15
How to execute a ssh script on Linux server from Windows through a bat script?


Hi All,

I have a situation here, I need a bat script for the windows user to do remote execution of shell script on Linux which will automate the rsync on the Linux server to the rest of the webservers. Can I know how do I go about doing that?


Thanks all in advance for ideas, suggestion to do it.
 
Old 08-31-2007, 04:27 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
One way to do this:
- Install Cygwin, as well as the following handy "C:\cygwin\launch.bat" script:
Code:
@echo off
C:
chdir C:\cygwin\bin
bash --login -i -c "%*"
- Run from your own .bat:
Code:
C:\cygwin\launch.bat ssh user@host "remotecommand"
Of course, you'll have to setup a passphrase-less key-based authentication to the host.

Yves.

Last edited by theYinYeti; 09-04-2007 at 07:43 AM.
 
Old 09-04-2007, 06:37 AM   #3
wanna13e
Member
 
Registered: Apr 2006
Posts: 45

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theYinYeti View Post
One way to do this:
- Install Cygwin, as well as the following handy "C:\cygwin\launch.bat" script:
Code:
@echo off
C:
chdir C:\_cygwin\bin
bash --login -i -c "%*"
- Run from your own .bat:
Code:
C:\cygwin\launch.bat ssh user@host "remotecommand"
Of course, you'll have to setup a passphrase-less key-based authentication to the host.

Yves.
Hi theYinYeti,

Thanks alot for your help and response. Can I know how do I do a passphrase-less key-based authentication? I'm new to this cygwin.
 
Old 09-04-2007, 07:38 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
another way, using Net::Telnet from Perl
 
Old 09-04-2007, 08:01 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
On the windows machine, open a Cygwin terminal (a command window). In it, follow these steps (copy/paste of my test):
Code:
You@PC ~
$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/You/.ssh/id_dsa): <type ENTER here>
Enter passphrase (empty for no passphrase): <type ENTER here>
Enter same passphrase again: <type ENTER here>
Your identification has been saved in /home/You/.ssh/id_dsa.
Your public key has been saved in /home/You/.ssh/id_dsa.pub.
The key fingerprint is:
e0:6a:23:1b:9b:40:bd:73:76:94:c0:e5:35:21:cb:a5 You@PC

You@PC ~
$ cat .ssh/id_dsa.pub | ssh remoteUser@remoteHost 'cat >>.ssh/authorized_keys'
remoteUser@remoteHost's password: <type remoteUser's password here + ENTER>
Along the way, it may ask if you definitely accept the remote host signature. Say yes.

Yves.

Last edited by theYinYeti; 09-04-2007 at 08:03 AM.
 
Old 04-07-2008, 02:16 AM   #6
zerocool22
Member
 
Registered: Feb 2008
Posts: 95

Rep: Reputation: 15
is it possible to provide a password in the bat file, so you don't need to enter the password each time?? Cause i want to make a .bat file with all users in that all login thrue ssh. So i want to add the password in the bat file for each user.

grtz
 
Old 04-07-2008, 02:42 AM   #7
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
You can also use "PuTTY", which may be easier for "Windows" users to get their heads around instead of Cygwin, and it may be something already install for access to the Linux servers.

plink Is part of PuTTY, and lets you issue commands through a SSH tunnel - just like ssh from Linux to Linux. Here's an example:-
Code:
C:\Program Files\Putty\plink.exe -ssh -2 -P 222 User@server ls -l /tmp
Just my 2c worth
 
Old 10-22-2009, 02:08 AM   #8
sangitajc
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
Cygwin ssh command in batch script

Hi,

I am using batch script. In that I am using cygwin ssh command to connect linux server from windows server. When i run that batch script form command prompt on windows server it gets connected to linux server without prompting for password. While when i try to run same command using scheduler it is prompting for password of linux server.

We have implemented key based authentication and saved key of windows server in linux server so it doesnt ask for password.

KIndly let me know if there is any way of providing password of linux server in batch script using Cygwin ssh command?

Thanks and Regards,
Sangita
 
Old 10-22-2009, 02:37 AM   #9
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
Download and look at Putty. One of the programs it comes with is called PuttyAgent and it can deliver keys when requested. Useful when using Windows programs to connect to Linux servers.
 
Old 10-22-2009, 03:23 AM   #10
sangitajc
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
Hi,
I have to use cygwin only.
I cant use any other tool.
My client has server setup like that.
Plz advice.

Regards,
Sangita
 
Old 10-22-2009, 08:49 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
Sounds to me like you haven't setup pub-keys for the scheduler; that's different user. Each user needs their own key; remember, its a substitution for a passwd, so the same security rules apply.
 
Old 10-23-2009, 12:09 AM   #12
sangitajc
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
But like i told, i have keys set up and I can connect to linux server without any password if i execute same batch script from command prompt, but if i use windows task scheduler, it prompts for linux server password.
 
Old 10-23-2009, 02:14 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
Like I said, you are userA, scheduler is UserB. Each 'userX' normally has their own separate different key, stored in a separate different dir.

Note also (separate issue) that sshd has an AllowUsers directive, so only specified users can login, regardless of key 'validity'...
 
Old 10-23-2009, 02:41 AM   #14
sangitajc
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
I will explain you more in detail.

I ahve written one batch script which uses cygwin ssh command to connetc to one linux server.
When i run that batch script from my windows server command prompt, it gets login to linux server without asking password since we have implemented public key authentication. This means there is no sshd configuration issue for that user.
While when i schedule the task to run that batch script it prompts for linux user password.
I am using UserA for the scheduled task to run under it and I am using UserB mentioned in the batch script to connetc linux server.

Difference is same thing work on command line but in scheduled task it prompts for linux server password.
I think now scenario should be clear to you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run bat file from Unix script??? gopi_20us Programming 10 09-14-2010 09:15 AM
Execute a windows command from inside a c-cgi-script leamassiot General 51 02-09-2006 10:06 AM
Windows and Linux Server. Issue with script. DeathGoth Programming 0 10-03-2004 03:45 PM
Remote Win Bat File execute Shell Script on AIX Server DriveMeCrazy AIX 5 05-26-2004 06:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration