-1

I have local Windows 10 and remote Ubuntu server.

I want to automate connection to server and write executable script witch connects by ssh to server and open new terminal from another server.

What it's supposed to look like

I double click on bat

enter image description here

And then script

  1. inits ssh connect
  2. writes password
  3. gives the user a terminal with a ready ssh connection.

That is, it mimics the following

enter image description here

Problems

  1. How to wait ssh password request? All commands executes immediately.
  2. (additional) can I write it in .sh script, run script, execute all in "start" terminal (from which I run .sh script) and then pass ssh control to invoked terminal?

It's best if someone writes a ready-made script

cheiser
  • 126
  • 1
  • 10

2 Answers2

0

Automatically enter SSH password with script

Answers:

  1. Direct answer - use expects. But sshpass is better. Also RSA-key can be used.
  2. Can`t tell anything.
cheiser
  • 126
  • 1
  • 10
0

Can be done without any 3rd party tools like this:

$env:TMPPW=Get-Content -Path 'secure_file.txt' ; $un='MyUserName'
$j=Start-Job -ScriptBlock{Start-Sleep -Seconds 1
(New-Object -ComObject wscript.shell).SendKeys("$env:TMPPW{ENTER}")}
& ssh.exe -q -4 -l $un 127.0.0.1 'whoami'
$env:TMPPW=([guid]::NewGuid()).Guid ; $env:TMPPW=$null
Phill
  • 11
  • 2