Skip to content

Troubleshooting SSH.NET

Gert Driesen edited this page Oct 6, 2017 · 10 revisions

If you encounter problems using the library, use this page as a reference on how to try find the source of the problem.

Please ensure you are using the latest release of SSH.NET. If you are already using the latest release, then download and compile the latest source code. Don't forget to update your project(s) reference(s).

Table of Contents

  1. How to narrow your problem down
  2. Frequently experienced SSH.NET exceptions
  3. System.Net.Socket exceptions
  4. NET TraceSource and TraceListeners
  5. SSH server assisted troubleshooting
  6. Log files
  7. Debugging mode
    1. Debug level
    1. Foreground process
  8. Unsupported remote systems
  9. Watchguard Firewall

How to narrow your problem down

By creating the simplest possible code that reproduce the problem you are having, it will be easier to debug and to pinpoint exactly where and why the problem is happening. So take some time to create code that can reproduce the problem.

Frequently experienced SSH.NET exceptions

"Key exchange negotiation failed"

The client and the server cannot find a common algoritm for exchanging keys.

To find out what kind of algorithms the server supports, you can put a breakpoint in the Start(Session, KeyExchangeInitMessage) method in Security\KeyExchange.cs.

"No suitable authentication method found to complete authentication."

The server is expecting a password/key authentication, but the client is sending a key/password, or an authentication mechanism that is not commonly supported by both client and server.

System.Net.Socket exceptions

Sometimes the server doesn't know what to do, and it just closes the connection and you'll get An existing connection was forcibly closed by the remote host exception.

If you get any of the following exception descriptions, it might be a problem on the computer you are running the program from, or the network you are on, and you should try your program on a different computer and network:

  • A blocking operation was interrupted by a call to WSACancelBlockingCall
  • Connection was lost
  • A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied

.NET TraceSource and TraceListeners

SSH.NET contains some tracing functionality, but at the time of writing, this is very limited.

The XML samples here should be put in the application configuration file under the configuration -> system.diagnostics element.

The samples here are based on samples posted in Durgaprasad Gorti's WebLog at Using System.Net Tracing.

System.Net.Sockets

The System.Net.Sockets namespace has some tracing options, this is how you enable it.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
            <sources>
                <source name="System.Net.Sockets" maxdatasize="1024">
                    <listeners>
                        <add name="MyTraceFile"/>
                    </listeners>
                </source>
                <source name="System.Net" maxdatasize="1024">
                    <listeners>
                        <add name="MyTraceFile"/>
                    </listeners>
                </source>
            </sources>
            <sharedListeners>
                <add
                  name="MyTraceFile"
                  type="System.Diagnostics.TextWriterTraceListener"
                  initializeData="SshNetTrace.log"
                />
            </sharedListeners>
            <switches>
                <add name="System.Net" value="Verbose" />
                <add name="System.Net.Sockets" value="Info" />
            </switches>
    </system.diagnostics>
</configuration>
Clone this wiki locally