sshnet / sshnet/SSH.NET

Connection reset when calling from within IIS

Open
#1,666 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

We have a legacy asp.net application that uses Renci.SshNet to upload files to a linux box. It's been working for years. We upgraded the version of ssh on the linux machine, and had to upgrade our application to the latest version of Recni.SshNet... 2025.0.0. Now, the application refuses to connect to the linux box. The only error we receive is "connection reset". The same error is reported on the server, with no additional information.

For credentials, we're using a .pem file located in a directory off the root of drive C. I've tried a dozen different permission combinations on this file. And I believe it's not a file permissions problem. The asp.net application that fails is able to read the contents of the .pem file.

I copied the code over to a test web application. And the code works there.... same code, same server, same application pool, same credentials, same file to upload, same destination server.

We also have similar code in a Windows service that uses Renci.SshNet to download the same file from the same linux machine. That code works.

I tried connecting from the windows iis server using a command line ssh with the same credentials. That works. I also tried to call the same command line ssh command from within the legacy asp.net application. That also fails with connection reset.

I can sometimes make this work by playing with various settings in applicationHost.config and web.config. Removing a seemingly unrelated module made it suddenly start working. It worked for a few minutes with maybe half a dozen successful upload attempts. So I put the module back in to verify that this was in fact the cause. And the upload quit working. So I took it back out, and it stayed not working. Sometimes I can get this same behavior by adding, removing, or changing certain entries in applicationHost.config or web.config. But it never sticks. After a few uploads, it stops working again. iisreset between every config file change. iisreset has no effect on whether this works or not.

I believe I'm chasing some kind of race condition in the unmanaged code in IIS. When I make a change to one of the config files, I think it forces iis to reload something in memory, allowing Renci.SshNet to work for a few minutes. Then it does something or loads something else which causes it to fail again.

I'm 100% stuck. At this point, my options are to redesign the file upload so that the asp.net application asks the windows service or something else outside the context of iis to do the upload for it. Or I have to remove Renci.SshNet and use some other library.

The main problem is that I have zero visibility. There's no information in any of the error messages to help me identify the root cause. I have to simply guess, again and again, and hope that I guess right in finding the cause. Can you offer any kind of assistance to get this working?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the connection reset from the legacy ASP.NET application under IIS, comparing it with the test web application, Windows service, and command-line SSH cases. Review the mentioned applicationHost.config and web.config changes and capture enough information to distinguish the IIS context from the working paths. Done means identifying a reproducible cause or actionable diagnostic for the reset.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.