Solved

DOS batch file: SSH connection, how to script to enter password when prompted?

Posted on 2004-08-26
11
2,225 Views
Last Modified: 2007-12-19
Hi,
I need to create a batch file on a Windows 2000 box which connects to linux box running an ssh (and ftp) server and uploads files in continuous loop for testing our connection.

I'm using putty's pscp to connect to transfer the files over. The problem is there is no way to specify the password on the pscp commandline. So I need to simulate its entry in the batch file as I can't have the user entering it manually everytime. This batch file isn't meant to be secure so yes the actual password will be exposed in the batch file. How can I do this? Here's what I have so far:

:START
pscp -r C:\data userName@192.168.0.2:/home/userName/
REM enter password when prompted
GOTO START


Thanks for any help!
0
Comment
Question by:patKC
11 Comments
 
LVL 6

Expert Comment

by:youre1m
ID: 11900521
This .vbs script will do it for you, save the below script to .vbs, ammend your details for domain\username and password, and the file name of course. See below link to my previously accepted answer.

http://www.experts-exchange.com/Operating_Systems/Win2000/Q_21025768.html

****************************************

Dim WshShell, scomputername
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oNetwork = WScript.CreateObject( "WScript.Network" )

srunme = "runas /userName@192.168.0.2:/home/userName/ pscp -r C:\data"

WshShell.Run srunme
WScript.Sleep 500
WshShell.Sendkeys "password" & chr(13)

****************************************
0
 
LVL 11

Expert Comment

by:lbertacco
ID: 11900778
Or you can create certificates and use certificate authentication instead of password authentication.
See "man ssh-keygen" on your link box
0
 
LVL 6

Expert Comment

by:bloemkool1980
ID: 11900905
create a key without a password. You can load this key in a batch it is still safer than a password included into a batch.
0
 

Expert Comment

by:cgwilder
ID: 11901227


PuTTY 0.52 (and late)r have a -pw command line switch, a la:

pscp -pw password -r C:\data userName@192.168.0.2:/home/userName/

If that doesn;t work for you, try:

echo password | pscp -r C:\data userName@192.168.0.2:/home/userName/
0
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.

 
LVL 34

Expert Comment

by:PsiCop
ID: 11907048
Yeah, I wouldn't bother with a password. Just generate a unique key to thw workstation and have SSH go straight in. Lot simpler.
0
 
LVL 4

Expert Comment

by:LittleRed1
ID: 11908721
If cgwilder's last suggestion doesn't work, create a text file with the password in and run the command like this:

pscp -r C:\data userName@192.168.0.2:/home/userName/ <password.txt
0
 
LVL 34

Expert Comment

by:PsiCop
ID: 12030759
Hello?
0
 
LVL 34

Expert Comment

by:PsiCop
ID: 13676189
Fine by me
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13692566
PAQed with no points refunded (of 125)

modulo
Community Support Moderator
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
AIX  NFS  question 5 101
cat /etc/debian_version returns stretch/sid instead of version 12 155
Mac Laptop - Water Spill 12 110
IBMi supported MySQL versions. 2 29
Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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