2

I am trying to make a batch file which connects to my router via SSH and executes some commands. The batch file currently looks like:

ssh [email protected]
configure
etc.....

When I run the batch file the first line executes, and then the command window asks

[email protected]'s password:

After inputting the password, the second line does not execute (I imagine this is obvious to someone who knows what they're doing)

I'm looking for a solution that either lets me manually enter the password and then lets the script continue, or one where the script enters the password itself.

6
  • 1
    Possible duplicate of Automatically enter SSH password with script Commented Jul 14, 2018 at 19:47
  • How would the remote host (which is not running the script) know what commands are in the script? Commented Jul 14, 2018 at 19:57
  • Also, that question may be a duplicate of the question in the title, but it is certainly not a duplicate of the question in the contents. Commented Jul 14, 2018 at 19:58
  • Please edit your question to show the relevant parts of your script. I.e., how it invokes ssh and then invokes the commands on the remote system. Commented Jul 14, 2018 at 21:43
  • Regarding how to avoid entering a password, see stackoverflow.com/a/43526842/13317 Commented Jul 14, 2018 at 21:45

1 Answer 1

0

Try this, which doesn't require any 3rd party tools:

$env:TMPPW=Get-Content -Path 'secure_file.txt'
$j=Start-Job -ScriptBlock{Start-Sleep -Seconds 1;
(New-Object -ComObject wscript.shell).SendKeys("$env:TMPPW{ENTER}")}
Get-Content -Path 'MyScript.txt' | & ssh.exe -q -4 -l user 192.168.1.1
$env:TMPPW=([guid]::NewGuid()).Guid ; $env:TMPPW=$null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.