PowerShell / Win32-OpenSSH

Win32 port of OpenSSH
7.41k stars 759 forks source link

add sshpass to PowerShell/Win32-OpenSSH #1943

Open insinfo opened 2 years ago

insinfo commented 2 years ago

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.

tgauth commented 2 years ago

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 = $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.

halim2209 commented 2 years ago

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

tgauth commented 2 years ago

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

matso42 commented 1 year ago

@tgauth Should this one be closed?

insinfo commented 1 year ago

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 commented 1 year ago

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

dkrahmer commented 1 year ago

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

insinfo commented 1 year ago

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

dkrahmer commented 1 year ago

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

insinfo commented 1 year ago

@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

dkrahmer commented 1 year ago

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

Spitfire1900 commented 9 months ago

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.

insinfo commented 9 months ago

@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

felipecrs commented 7 months ago

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.