Closed bryanmurtha closed 6 years ago
OpenSSL? Posh-SSH does not support x509 certs but OpenSSH key files. Never tested the module with a key without a passphrase, it is prohibited in my work environment and all of my customers do to the inherit dangers. Will set a test server to test with
Tested with a OpenSSH key generated on a Ubuntu 16.04 system and was able to connect but noticed a bug related to relative path.
PS C:\Users\Carlos\Desktop> New-SFTPSession -ComputerName 192.168.1.230 -Credential carlos -KeyFile C:\Users\Carlos\Desktop\id_rsa -Verbose
VERBOSE: Using SSH Key authentication for connection.
VERBOSE: Fingerprint for 192.168.1.230: be:3a:9a:e4:db:b5:25:cd:bc:2b:2d:5d:cb:9f:26:8c
Server SSH Fingerprint
Do you want to trust the fingerprint be:3a:9a:e4:db:b5:25:cd:bc:2b:2d:5d:cb:9f:26:8c
[] Y [] N [?] Help (default is "N"): y
SessionId Host Connected
--------- ---- ---------
0 192.168.1.230 True
blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hey thanks Carlos, Appreciated. I used Puttygen on Windows 10. I did add a password to the private key. It complains that it doesn't have one. The path I was using was D:\test1\Private.ppk so that shouldn't be the issue. I just don't have an idea. I tried exporting the key in OpenSSL format. That didn't work either.
Sent from Yahoo Mail for iPhone
On Tuesday, April 4, 2017, 6:43 PM, Carlos Perez notifications@github.com wrote:
Tested with a OpenSSH key generated on a Ubuntu 16.04 system and was able to connect but noticed a bug related to relative path.
`PS C:\Users\Carlos\Desktop> New-SFTPSession -ComputerName 192.168.1.230 -Credential carlos -KeyFile C:\Users\Carlos\Desktop\id_rsa -Verbose VERBOSE: Using SSH Key authentication for connection. VERBOSE: Fingerprint for 192.168.1.230: be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c
Server SSH Fingerprint Do you want to trust the fingerprint be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c [] Y [] N [?] Help (default is "N"): y
SessionId Host Connected 0 192.168.1.230 True
`
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
So you used puttygen to import then export as openssh, on a linux box extracted the pub key and added it to authorizedkeys ?
Open PuttyGen Click Load Load your private key Go to Conversions->Export OpenSSHand export your private key Copy your private key to ~/.ssh/id_dsa (or id_rsa). Create the RFC 4716 version of the public key using ssh-keygen
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub Convert the RFC 4716 version of the public key to the OpenSSH format:
ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub
Sent from my iPhone
On Apr 4, 2017, at 6:58 PM, bryanmurtha notifications@github.com wrote:
blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hey thanks Carlos, Appreciated. I used Puttygen on Windows 10. I did add a password to the private key. It complains that it doesn't have one. The path I was using was D:\test1\Private.ppk so that shouldn't be the issue. I just don't have an idea. I tried exporting the key in OpenSSL format. That didn't work either.
Sent from Yahoo Mail for iPhone
On Tuesday, April 4, 2017, 6:43 PM, Carlos Perez notifications@github.com wrote:
Tested with a OpenSSH key generated on a Ubuntu 16.04 system and was able to connect but noticed a bug related to relative path.
`PS C:\Users\Carlos\Desktop> New-SFTPSession -ComputerName 192.168.1.230 -Credential carlos -KeyFile C:\Users\Carlos\Desktop\id_rsa -Verbose VERBOSE: Using SSH Key authentication for connection. VERBOSE: Fingerprint for 192.168.1.230: be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c
Server SSH Fingerprint Do you want to trust the fingerprint be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c [] Y [] N [?] Help (default is "N"): y
SessionId Host Connected 0 192.168.1.230 True
`
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hi Carlos, thanks for the reply. I don't have control of the Linux server. It's a third party that provides us data files. I already gave them the key I generated and it's working using the key I have and psftp and Pageant. But Pageant crashes all the time and the script will just hang prompting for a password. That's why I'm trying to get a different solution together. I will see what I can do with it tomorrow. Thanks again. Bryan
Sent from Yahoo Mail for iPhone
On Tuesday, April 4, 2017, 9:03 PM, Carlos Perez notifications@github.com wrote:
So you used puttygen to import then export as openssh, on a linux box extracted the pub key and added it to authorizedkeys ?
Open PuttyGen Click Load Load your private key Go to Conversions->Export OpenSSHand export your private key Copy your private key to ~/.ssh/id_dsa (or id_rsa). Create the RFC 4716 version of the public key using ssh-keygen
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub Convert the RFC 4716 version of the public key to the OpenSSH format:
ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub
Sent from my iPhone
On Apr 4, 2017, at 6:58 PM, bryanmurtha notifications@github.com wrote:
blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hey thanks Carlos, Appreciated. I used Puttygen on Windows 10. I did add a password to the private key. It complains that it doesn't have one. The path I was using was D:\test1\Private.ppk so that shouldn't be the issue. I just don't have an idea. I tried exporting the key in OpenSSL format. That didn't work either.
Sent from Yahoo Mail for iPhone
On Tuesday, April 4, 2017, 6:43 PM, Carlos Perez notifications@github.com wrote:
Tested with a OpenSSH key generated on a Ubuntu 16.04 system and was able to connect but noticed a bug related to relative path.
`PS C:\Users\Carlos\Desktop> New-SFTPSession -ComputerName 192.168.1.230 -Credential carlos -KeyFile C:\Users\Carlos\Desktop\id_rsa -Verbose VERBOSE: Using SSH Key authentication for connection. VERBOSE: Fingerprint for 192.168.1.230: be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c
Server SSH Fingerprint Do you want to trust the fingerprint be:3a:9a:e4:db:b5:25 💿 bc:2b:2d:5d:cb:9f:26:8c [] Y [] N [?] Help (default is "N"): y
SessionId Host Connected 0 192.168.1.230 True
`
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
any progress on this?
Closing for now. Reopen if this is still an issue.
I can connect to WinSCP and it prompts me for a passphrase. So does Pageant if I open the key there and use it with psftp, which is the solution I'm trying to replace with POSH-SSH. I tried opening the key in Puttygen and exporting it as an OpenSSL format as well as save it as a .pkk. I tried pointing to it directly on the file system as well as defining the key as a [string[]] array. ``
$sftpUser = “Intesasanpaolo” $sftpServer = “68.64.35.168” $LocalFile = “d:\data\filetoupload.txt” $encryptedSource = Get-Content D:\Test1\Private.ppk | ConvertTo-SecureString $CredSource = New-Object System.Management.Automation.PsCredential("Intesasanpaolo", $encryptedSource) $Session = New-SFTPSession -ComputerName $sftpServer -Credential $CredSource -AcceptKey
$sftpPass = ConvertTo-SecureString -String “Es84G7tzr” -AsPlainText -Force $sftpCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $sftpUser, $sftpPass $sftpSession = New-SFTPSession -ComputerName $sftpServer -Credential $sftpCred
Set-SFTPFile -SFTPSession $sftpSession -LocalFile $Localfile -RemotePath “/Outbound/” -Overwrite
Define Serve Name
$ComputerName = "68.64.35.168"
Define UserName
$UserName = "Intesasanpaolo"
Define the Private Key file path
$KeyFile = "D:\Test1\TestKey" $nopasswd = new-object System.Security.SecureString
Set Credetials to connect to server
$Credential = New-Object System.Management.Automation.PSCredential ($UserName, $nopasswd)
Establish the SFTP connection
$SFTPSession = New-SFTPSession -ComputerName $ComputerName -Credential $Credential -KeyFile $KeyFile
Set local file path, SFTP path, and the backup location path which I assume is an SMB path
$FilePath = "C:\Sumit\SFTP1.txt" $SftpPath = 'data/'
Upload the file to the SFTP path
Set-SFTPFile -SessionId $SFTPSession.SessionID -LocalFile $FilePath -RemotePath $SftpPath
Disconnect SFTP session
$SFTPSession.Disconnect()