How to execute a ssh script on Linux server from Windows through a bat script?
ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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
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?
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.