SessionOptions passphrase

Advertisement

kulicny
Joined:
Posts:
6
Location:
New Hampshire, US

SessionOptions passphrase

I am scripting in PowerShell. I send the following commands using SessionOptions and keep getting the results below from the log file. I've successfully connected with the WinSCP client app using the PPK and the passphrase. I just can't get it to work via the PowerShell script. I'm not sure what I'm missing or should be doing differently.
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "<my host name>"
        UserName = "<myusername>"
        PrivateKeyPassphrase = "<mypassphrase>"
        SshPrivateKeyPath = "<pathformyPPK>"
        SshHostKeyFingerprint = "<ssh rsa fingerprint>"
}
This is the from the log file:
Reading key file "<pathformyPPK>"
Using username "<myusername>".
Script: Using username "<myusername>".
Server offered these authentication methods: publickey
Offered public key
Offer of public key accepted
Authenticating with public key "<mypublickey>"
Script: Authenticating with public key "<mypublickey>".
Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "<mypublickey>": ")
Using configured passphrase.
Wrong passphrase
Script: Wrong passphrase.

Reply with quote

Advertisement

kulicny

update

It appears to have something to do with Pageant. I did a bit more research, and after adding the private key and passphrase to Pageant, it executes as expected. I wouldn't have expected to have to have Pageant running and the ppk in there to make this to work. Plus, I still had to supply the passphrase in the script, so I'm not sure this is the "correct" solution. But it did connect and put the file.

Reply with quote

kulicny
Joined:
Posts:
6
Location:
New Hampshire, US

logs

Here are the requested logs. Let me know if you need anything else.
  • IROLftp.log (7.23 KB, Private file)
Description: Script log
  • GUI.log (7.77 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: logs

I believe you are either using a different key or a different passphrase. It's hard to imagine any other explanation.

Are there any special characters in your passphrase? Did you test it with some very trivial one ("abc")?

Enable password logging in both GUI and .NET, to check if WinSCP really gets the passphrase that it should.

Reply with quote

Advertisement

kulicny

RE:

Well, you were right. There was a special character in the passphrase. I didn't realize that it would interpret the character as special while setting SessionOptions. Enclosing the PrivateKeyPassphrase in single quotes vs double quotes solved it and it passes the entire string. Thanks for the suggestion and apologies for not having considered that sooner.

Reply with quote

martin
Site Admin
martin avatar

Re: RE:

Do you mean that PowerShell interpreted some special character (dollar sign possibly?) in your double-quoted string?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum