darkoperator / Posh-SSH

PowerShell Module for automating tasks on remote systems using SSH
BSD 3-Clause "New" or "Revised" License
979 stars 226 forks source link

Session operation has timed out inside Azure Automation #83

Closed oliverbock closed 8 years ago

oliverbock commented 8 years ago

I am trying to use Posh-SSH in an Azure Automation Runbook in order to run something on a Linux VM. My script

$password = Convertto-SecureString -String "xxxxxxx" -AsPlainText -Force
$cred = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList numbers, $password
$ssh = New-SSHSession -ComputerName "example.com" -Credential $cred -AcceptKey -ConnectionTimeOut 100
$(Invoke-SSHCommand -Index 0 -Command "echo dog").Output 

runs fine from my command line, but in Azure Automation I get the error

Session operation has timed out

which is why I extended the timeout. Do you know whether Posh-SSH operate in this environment?

oliverbock commented 8 years ago

The full error is

New-SSHSession : Session operation has timed out
At line:3 char:8
+ $ssh = New-SSHSession -ComputerName "example.com" -Credentia ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-SSHSession], SshOperationTimeoutException
    + FullyQualifiedErrorId : Renci.SshNet.Common.SshOperationTimeoutException,SSH.NewSshSession
oliverbock commented 8 years ago

I have had more luck with this SSH client implementation for PowerScript.

darkoperator commented 8 years ago

I don’t use Azure so no clue there. Only thing that comes to mind is they auth it does to check if the key it is one it knows about and you are not auto accepting the key.

On Dec 17, 2015, at 7:25 PM, oliverbock notifications@github.com wrote:

I have had more luck with this SSH client implementation for PowerScript https://gallery.technet.microsoft.com/scriptcenter/SSH-PowerShell-Module-17616e1a.

— Reply to this email directly or view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-165614201.

oliverbock commented 8 years ago

Thanks. Am I not accepting the key properly? I included "-AcceptKey" alone because when I tried "-AcceptKey 1" or "-AcceptKey $true" then PowerShell (v3.0) complains about unexpected command-line parameters.

urlocalguru commented 8 years ago

basic usage would be New-SSHSession -ComputerName fooserver -AcceptKey

I have run into issues with devices with a different key then what was previously accepted (due to re-image etc) and have to either cleanup after each script with the Remove-SSHTrustedHost function. Or I can purge all keys with foreach($i in Get-SSHTrustedHost){Remove-SSHTrustedHost -SSHHost $i.SSHHost -Verbose}

darkoperator commented 8 years ago

Thinking if I should add a -Force parameter that will not check the key at all and simply accept a session if the credentials are valid

alfa164ls commented 8 years ago

Drd3 On 28 Feb 2016 02:06, "Carlos Perez" notifications@github.com wrote:

Thinking if I should add a -Force parameter that will not check the key at all and simply accept a session if the credentials are valid

— Reply to this email directly or view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-189764397 .

slavizh commented 8 years ago

It would be good if you can fix this Carlos so we can use the full capabilities of this module in Azure Automation. Besides that it is a great module and thank you for your work!

darkoperator commented 8 years ago

added -Force on the 1_7_5 branch, once I have some other issues fixed for that version I will push the version to GitHub and to the Gallery.

darkoperator commented 8 years ago

Uploaded 1.7.5 to the gallery

rrbruin commented 7 years ago

Even with the -Force parameter I am getting a timeout..

darkoperator commented 7 years ago

Anything on the target logs?

Sent from my iPhone

On May 30, 2017, at 7:17 AM, rrbruin notifications@github.com wrote:

Even with the -Force parameter I am getting a timeout..

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

rrbruin commented 7 years ago

The target is a Fortigate firewall. But at the moment it's not producing any usable logs in the GUI. I will try to get more info.

Using the Posh-SSH module in a Powershell ISE session works perfect when connecting to the Fortigate. It only fails when I use it from a Azure runbook.

darkoperator commented 7 years ago

The module requires to be ran under the context of a user since it accesses the registry for some tasks, do Azure Runbooks run under a user?

On May 30, 2017, at 8:16 AM, rrbruin notifications@github.com wrote:

The target is a Fortigate firewall. But at the moment it's not producing any usable logs in the GUI. I will try to get more info.

Using the Posh-SSH module in a Powershell ISE session works perfect when connecting to the Fortigate. It only fails when I use it from a Azure runbook.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-304859945, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HhXvWIMCnDcWfmGVxYlEGjq0y6rVks5r_AiVgaJpZM4G3IIC.

rrbruin commented 7 years ago

No, it completely runs inside the Azure environment. So, I don’t think there is even a register to access.

I will try to run the runbook tough an Azure HybridWorker. In this case, it will run on a Windows VM using a service account.

This will add extra step which I rather avoid. But if that’s the only way to get it working, I have no choice. Or I should look for another SSH solution

I will let you know.

darkoperator commented 7 years ago

Ok, I do know the dev branch of version 2.0 does not have this restriction but 2.0 is not ready yet and it will introduce braking changes, that is why it will be a major number release

On May 30, 2017, at 10:15 AM, rrbruin notifications@github.com wrote:

No, it completely runs inside the Azure environment. So, I don’t think there is even a register to access.

I will try to run the runbook tough an Azure HybridWorker. In this case, it will run on a Windows VM using a service account.

This will add extra step which I rather avoid. But if that’s the only way to get it working, I have no choice. Or I should look for another SSH solution

I will let you know.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-304891701, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0Hqtnr52oxaljOus2Cc2FC28q3Zweks5r_CR8gaJpZM4G3IIC.

darkoperator commented 7 years ago

Under what context does Azure Automation run under? Never used Azure so I have little knowledge on it.

On Mar 21, 2016, at 8:48 AM, Stanislav Zhelyazkov notifications@github.com wrote:

It would be good if you can fix this Carlos so we can use the full capabilities of this module in Azure Automation. Besides that it is a great module and thank you for your work!

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-199257105

rrbruin commented 7 years ago

I think it will run under some kind of SYSTEM account. It does work when I use the Azure HybridWorker option. For now I can use this as an option.

rbyrnedugan commented 7 years ago

I am running into this issue as well. Do you have any information on when version 2.0 will be released?

Flodu31 commented 7 years ago

Hello, I've the same problem on my Azure Automation account, with the -Force parameter, any idea? Thanks

rbyrnedugan commented 7 years ago

The only workaround I found was to use the Azure HybridWorker option as @rrbruin mentioned

darkoperator commented 7 years ago

Version 2 was released are you using the latest version?

Sent from my iPhone

On Sep 14, 2017, at 10:01 AM, rbyrnedugan notifications@github.com wrote:

The only workaround I found was to use the Azure HybridWorker option as @rrbruin mentioned

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

Flodu31 commented 7 years ago

Yes I downloaded it this afternoon.

Florent

From: Carlos Perez notifications@github.com Reply-To: darkoperator/Posh-SSH reply@reply.github.com Date: Thursday, 14 September 2017 at 16:33 To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Flodu31 florent.appointaire@gmail.com, Comment comment@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Session operation has timed out inside Azure Automation (#83)

Version 2 was released are you using the latest version?

Sent from my iPhone

On Sep 14, 2017, at 10:01 AM, rbyrnedugan notifications@github.com wrote:

The only workaround I found was to use the Azure HybridWorker option as @rrbruin mentioned

— You are receiving this because you modified the open/close state. 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.

darkoperator commented 7 years ago

The to be honest dont know what I could else do. I’m no longer checking the resgitry or trying to open it. Since I do not have Azure access there is no way for me to test to see what else it could be. Does it at least give you a specific error?

On Sep 14, 2017, at 11:16 AM, Flodu31 notifications@github.com wrote:

Yes I downloaded it this afternoon.

Florent

From: Carlos Perez notifications@github.com Reply-To: darkoperator/Posh-SSH reply@reply.github.com Date: Thursday, 14 September 2017 at 16:33 To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Flodu31 florent.appointaire@gmail.com, Comment comment@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Session operation has timed out inside Azure Automation (#83)

Version 2 was released are you using the latest version?

Sent from my iPhone

On Sep 14, 2017, at 10:01 AM, rbyrnedugan notifications@github.com wrote:

The only workaround I found was to use the Azure HybridWorker option as @rrbruin mentioned

— You are receiving this because you modified the open/close state. 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 modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/83#issuecomment-329515041, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HpPOG8GTJnuWF2gytVv1ApH3hdfZks5siUNcgaJpZM4G3IIC.

Flodu31 commented 7 years ago

No, I've exactly the same. I'll try another module to see if the problem is the same and will keep you updated.

Flodu31 commented 7 years ago

I'll use the workaround of @rbyrnedugan because I can't find a solution to this problem.

yfrindel commented 5 years ago

I had the same issue. It works with a "-ConnectionTimeout" value