22

I want to run sshpass command from my Windows to remote Linux server. I use this command:

sshpass -p 'password' ssh ldap.nextstep4it.com -l root -o StrictHostKeyChecking=no

But my cmd return below error statement:

'sshpass' is not recognized as an internal or external command, operable program or batch file.

I think this is because Windows don't have sshpass package as Linux do. From Linux I have to install sshpass package to be able to run this command.

Is there anybody know how to run sshpass command through Windows command line?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ridzuan Adris
  • 1,192
  • 2
  • 13
  • 32

6 Answers6

15

You cant run sshpass in windows. You can however use putty via the windows command line, to achieve the same thing.

putty -load "host" -l username -pw password

Also you can upload files via command line (with a password) using WinSCP

winscp /command "option batch abort" "option confirm off" "open sftp://user:password@example.com/" "put examplefile.txt /home/user/" "exit"
Jay Shepherd
  • 503
  • 4
  • 6
  • what should I use as winscp? For example the path to winscp.exe? – Francesco Pegoraro Apr 29 '19 at 11:07
  • 1
    It's opening a "Putty Configuration" window for me. I am currently on git bash. I also tried the command via windows command prompt and powershell. It always opens a "Putty Configuration" as if it was invoked without arguments. What's the issue here? – Adze Feb 04 '21 at 17:58
  • `putty -ssh hostname -l username -pw password` This works better, in a way that it opens another terminal window and auto logs in to the server. Is there any way to make this even better by asking it to not open another window and just login within git bash? – Adze Feb 04 '21 at 18:07
  • 2
    `plink -ssh hostname -l username -pw password` This is best. Opens within my git bash terminal and auto logs in. Exactly what I needed. – Adze Feb 04 '21 at 18:16
11

Instead of OpenSSH ssh, you can use PuTTY plink. It's command line equivalent of PuTTY and has very similar command-line syntax as OpenSSH ssh. But on top of it, it has -pw switch for providing a password.

The plink equivalent of your ssh call is:

plink ldap.nextstep4it.com -l root -pw password

You absolutely should not use -o StrictHostKeyChecking=no to blindly accept all host keys. That is a security flaw. You lose a protection against MITM attacks. Instead, with plink, you can use -hostkey switch to set the fingerprint of the expected host key.


Similarly:

Both have the -pw switch.

Alternatively, both for SCP and SFTP, you can use my WinSCP SFTP/SCP client. WinSCP also supports providing the password on command-line/in script. And there's a guide for converting OpenSSH sftp script to WinSCP script.


No matter, if you use OpenSSH, PuTTY or WinSCP, it is always better is to use public key authentication than the password.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
7

Using Windows Subsystem for Linux (WSL); first go to Settings->Turn Windows Features On or Off->Enable Windows Subsystem for Linux, then download and install Ubuntu or another Linux from the Microsoft Store.

To access WSL from cmd.exe type bash or wsl

sudo apt-get install sshpass

sshpass -p passxxxx ssh user@ip.address 'touch newfileonserver.txt'

To invoke from a windows environment, eg. cmd.exe or Process.Start()

bash -c "sshpass -p passxxxx ssh user@ip.address 'touch newfileonserver.txt' "
patrick
  • 16,091
  • 29
  • 100
  • 164
4

You can install QtdSync for Windows.

This will contain the sshpass.exe

  • 1
    This did not work for me, there was still a password prompt even when I supplied the password using the `-p` flag. – hb20007 Jun 25 '20 at 10:51
1

Just install cygwin in your Windows, then download sshpass and compile/install it, the whole process is quick and easy, it works great in my environment.

July
  • 855
  • 4
  • 11
  • 22
-3

You can rather try putty.

Download it from here

Or you can install cygwin and install sshpass, but that would be a larger task.

So, if you need a passwordless login then with putty you can use puttygen, which you can install from the same link provided above.

PradyJord
  • 2,136
  • 12
  • 19
  • thank you for the answer Jord, but it did not solve my question. what i am trying to do is to run sshpass package into windows command prompt. i appreciate your answer by the way – Ridzuan Adris May 05 '14 at 00:52