0

IMPORTANT: that this is not just for this case, I want to create for example .bats to automate some things, then I would like to know how to make him wait for the command to return and interpret my next line as the answer.

How i can do .bat file answer one question comes of a command, for example:

I run it:

ssh -p port user@host

And then it require password, how in the next line i do it answer programatycally in same .bat?

I tryied:

ssh -p port user@host
PASSWORD

But dont works, he discart my PASSWORD and require it in the next line.

Woton Sampaio
  • 469
  • 6
  • 24
  • 3
    Possible duplicate of [Execute ssh with password authentication via windows command prompt](https://stackoverflow.com/questions/12118308/execute-ssh-with-password-authentication-via-windows-command-prompt) – Compo Aug 15 '19 at 16:08
  • The `cmd` tag is for Microsoft Windows. Are you running on Windows? It not, please remove the `cmd` tag. If you are on Windows, from where did you get the `ssh` command? – lit Aug 15 '19 at 18:48

1 Answers1

1

I don't believe there is a way to save your password. However, you may be able to set up key based authentication so that a password is not required.

> ssh-keygen

> ssh-copy-id -i ~/.ssh/mykey user@host

See https://www.ssh.com/ssh/copy-id for more info

Brojowski
  • 65
  • 7
  • But understand, what I really want is for my next line to be interpreted as the answer to the question, which is not basically just ssh, it could be a form for example, you know? – Woton Sampaio Aug 15 '19 at 16:10
  • Check out the link @Compo posted. It looks like `sshpass` might be right for you. – Brojowski Aug 15 '19 at 16:15