amitshowry 0 Newbie Poster

I had written a script to login to some terminals and do some basic commands remotely.

It fails at password entry.
*******************************************************************

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cygwin"

' Give Cygwin time to load
WScript.Sleep 2000
a=Array(112)
For Each i In a
WshShell.SendKeys "`ssh user@XX.XX.XX.XX" & i & " 'hostname;ps aux' " & "{ENTER}"
WScript.Sleep 1000
WshShell.SendKeys "******" & "{ENTER}"
WScript.Sleep 2000

Next
***************************************************************
It's taking till password step fails very next.

I had double confirmed the password.

Dani AI

Generated

SendKeys is unreliable for automating an SSH password prompt because OpenSSH asks for the password from the controlling terminal (TTY) instead of a normal Windows text control, and many Cygwin terminals (mintty or a native console wrapper) do not accept synthetic Windows keystrokes the way a standard Win32 edit box would. In short: the password prompt often ignores SendKeys and the automation will fail whenever focus shifts or the terminal consumes input directly.

Better options (ordered by safety and reliability):

  • Use SSH keys with an agent (recommended). Create a key pair and install the public key on the server, then your script can call ssh non‑interactively:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_script
ssh-copy-id user@host.example.com
ssh user@host.example.com 'hostname; ps aux'
  • If keys are not possible, run the action from inside Cygwin using Expect (safer than SendKeys). Example Expect script:
#!/usr/bin/expect -f
set timeout 10
spawn ssh user@host.example.com "hostname; ps aux"
expect "assword:"
send "your_password\r"
expect eof

Make it executable and run it under Cygwin.

  • As a last resort on Windows-only setups, PuTTY's plink can pass a password on the command line (-pw) or use Pageant for key handling. Note: -pw and storing plaintext passwords are insecure.

Practical tips: accept the host key interactively first (or use -o StrictHostKeyChecking=no carefully), avoid saving plaintext passwords, and prefer ssh-agent/Pageant for passphrases. Avoid WshShell.SendKeys for terminal I/O — use key auth, Expect, sshpass, or plink depending on your security constraints.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.