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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-31-2007, 04:18 AM
|
#1
|
|
Member
Registered: Apr 2006
Posts: 45
Rep:
|
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.
|
|
|
|
08-31-2007, 04:27 AM
|
#2
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
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.
|
|
|
|
09-04-2007, 06:37 AM
|
#3
|
|
Member
Registered: Apr 2006
Posts: 45
Original Poster
Rep:
|
Quote:
Originally Posted by theYinYeti
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.
|
|
|
|
09-04-2007, 07:38 AM
|
#4
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
another way, using Net::Telnet from Perl
|
|
|
|
09-04-2007, 08:01 AM
|
#5
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
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.
|
|
|
|
04-07-2008, 02:16 AM
|
#6
|
|
Member
Registered: Feb 2008
Posts: 95
Rep:
|
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
|
|
|
|
04-07-2008, 02:42 AM
|
#7
|
|
Member
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569
Rep:
|
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  
|
|
|
|
10-22-2009, 02:08 AM
|
#8
|
|
LQ Newbie
Registered: Oct 2009
Posts: 4
Rep:
|
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
|
|
|
|
10-22-2009, 02:37 AM
|
#9
|
|
Member
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569
Rep:
|
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.
|
|
|
|
10-22-2009, 03:23 AM
|
#10
|
|
LQ Newbie
Registered: Oct 2009
Posts: 4
Rep:
|
Hi,
I have to use cygwin only.
I cant use any other tool.
My client has server setup like that.
Plz advice.
Regards,
Sangita
|
|
|
|
10-22-2009, 08:49 PM
|
#11
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,988
|
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.
|
|
|
|
10-23-2009, 12:09 AM
|
#12
|
|
LQ Newbie
Registered: Oct 2009
Posts: 4
Rep:
|
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.
|
|
|
|
10-23-2009, 02:14 AM
|
#13
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,988
|
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'...
|
|
|
|
10-23-2009, 02:41 AM
|
#14
|
|
LQ Newbie
Registered: Oct 2009
Posts: 4
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:38 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|