"sshpass is not recognized" on Windows
Asked Answered
L

6

27

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?

Lymphosarcoma answered 2/5, 2014 at 2:4 Comment(0)
H
18

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:[email protected]/" "put examplefile.txt /home/user/" "exit"
Hispanicize answered 15/5, 2014 at 4:55 Comment(4)
what should I use as winscp? For example the path to winscp.exe?Harpoon
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?Artichoke
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?Artichoke
plink -ssh hostname -l username -pw password This is best. Opens within my git bash terminal and auto logs in. Exactly what I needed.Artichoke
I
15

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 (there's also -pwfile switch).

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 and -pwfile switches.

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.

Ideally answered 28/9, 2020 at 18:52 Comment(1)
easiest solution thanksNeutralization
I
10

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 [email protected] 'touch newfileonserver.txt'

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

bash -c "sshpass -p passxxxx ssh [email protected] 'touch newfileonserver.txt' "
Idiotic answered 30/3, 2020 at 17:8 Comment(1)
Yeah, and the command will be: wsl -- sshpass ...Tweedsmuir
R
5

You can install QtdSync for Windows.

This will contain the sshpass.exe

Ripping answered 10/8, 2016 at 13:44 Comment(1)
This did not work for me, there was still a password prompt even when I supplied the password using the -p flag.Cockaleekie
E
0

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.

Expedition answered 22/12, 2014 at 4:44 Comment(2)
30 minutes to install make & gcc and run the installation. Thanks :)Melanymelaphyre
What happens if u dont have gcc and not easy to install, cant believe this binary is so difficult to findCreekmore
S
-5

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.

Schaerbeek answered 2/5, 2014 at 9:58 Comment(1)
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 wayLymphosarcoma

© 2022 - 2024 — McMap. All rights reserved.