Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to use ssh in c# but getting below error.

No connection could be made because the target machine actively refused it.
using (var client = new SshClient("hostname", "userid", "pwd"))
                {
                    client.Connect();
                  
                    client.Disconnect();
                }


What I have tried:

I tried to connect to pass host id and pwd but still not able to connect
we want to execute some cmd commands once ssh connect
Posted
Comments
Chris Copeland 28-Sep-22 6:52am    
If you're trying to connect to the same machine, use 127.0.0.1 rather than localhost. Otherwise, a connection being refused typically means a firewall has prevented the port being accessed, or the port is inaccessible for some reason.
Member 15418280 29-Sep-22 5:47am    
I changed host name 127.0.0.1 but still getting same error
Member 11392518 2-Oct-22 8:09am    
Are you able to connect using some common SSH client from the same machine? Are you sure that you're using the default port 22 in the SSH daemon config?
I just tried similar code (after resolving the dependency to Renci.SshNet) and it works fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900