Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

add sshpass to PowerShell/Win32-OpenSSH

Open insinfo opened this issue 2 years ago • 14 comments

I'm used to using this on debian and now I'm needing to use it on windows with PowerShell and I didn't find any other option.

insinfo avatar May 24 '22 11:05 insinfo

https://github.com/PowerShell/openssh-portable/tree/latestw_all/regress/pesterTests/utilities/askpass_util

To use it, set the following environment variables: $env:ASKPASS_PASSWORD = <ssh_user_password> $env:SSH_ASKPASS_REQUIRE = "force" $env:SSH_ASKPASS = <path\to\askpass.exe>

With those set, the ssh_user should be able to ssh without being prompted for the password, as it is provided by askpass.

Let us know if that helps.

tgauth avatar May 26 '22 20:05 tgauth

@tgauth, where to get the askpass.exe from in order to set its path in $env:SSH_ASKPASS?

halim2209 avatar Oct 24 '22 16:10 halim2209

https://github.com/PowerShell/openssh-portable/blob/latestw_all/regress/pesterTests/utilities/askpass_util/askpass_util.exe

tgauth avatar Oct 24 '22 16:10 tgauth

@tgauth Should this one be closed?

matso42 avatar Nov 25 '22 11:11 matso42

the ideal is to have a solution that doesn't need to use environment variables as in Linux. mainly for senarios to execute commands in the terminal via compiled code or scripts where you don't want to put this information in the environment variables

insinfo avatar Nov 25 '22 14:11 insinfo

not to mention that askpass.exe is not natively available in PowerShell

insinfo avatar Nov 25 '22 14:11 insinfo

I added a password CLI argument for SSH and SCP. I am using it on Windows but it should work on other OSs too.

To specify a password: -Z password

My fork: https://github.com/dkrahmer/openssh-portable

dkrahmer avatar May 17 '23 22:05 dkrahmer

@dkrahmer good job, do you have the compiled binaries for download?

insinfo avatar May 30 '23 14:05 insinfo

I created a repo release that includes Win32 binaries. https://github.com/dkrahmer/openssh-portable/releases/

dkrahmer avatar May 30 '23 17:05 dkrahmer

@dkrahmer I downloaded your compiled version but it's not working, nothing happens when I run it image

I went to open the executable in the Visual Studio debugger and saw the message that is requesting libcrypto.sll image

insinfo avatar May 31 '23 00:05 insinfo

Sorry about that. I forgot to include libcrypto.dll which must be placed in the same directory. I added it to the release.

dkrahmer avatar May 31 '23 01:05 dkrahmer

Suggestion. Install keyring with pipx and use it as a backend. This will use to Windows Generic Credential store to save your password. Unlike the Get-Credential PS commandlet there will be no prompt for password.

pipx install keyring
keyring set ssk_askpass askpass
# Password for 'askpass' in 'ssh_askpass': <Enter Password>
# Verify here
keyring get ssh_askpass askpass
# <Should print your password>

Create a askpass_keyring_util.bat with the content:

@echo off
keyring get ssh_askpass askpass

Set

$env:SSH_ASKPASS_REQUIRE = "force"
$env:SSH_ASKPASS = "<Path to askpass_keyring_util.bat>"`

Verify by initiating ssh connection.

Spitfire1900 avatar Jan 18 '24 20:01 Spitfire1900

@Spitfire1900 I prefer a simple solution like passing the password on the command line and not having to set environment variables or install Python

solution of @dkrahmer is the best option for me

insinfo avatar Jan 19 '24 12:01 insinfo

My personal opinion: sshpass is not part of OpenSSH's umbrella. It's a side project. I think you should ask it to provide Windows binaries rather than asking it to be included here.

felipecrs avatar Mar 13 '24 23:03 felipecrs