Can this be used to ssh like what is shown on this website?
The https://serveo.net/ website (yes their security certs seems to have expired on 2017) shows some ssh commands.
Well I want to be able to provide them programmatically in .net instead as windows does not come with ssh on all versions of windows.
Why don't you just mention the ssh commands you are having problems with right there together with your issue report, instead of trying to direct readers of your issue report to a website with an expired certificate (expired since 2017 already, which would indicate the (former) owner has abandoned this site quite some time ago; who knows what malevolent crap has been infesting it since then...)
Well it was basically port forwarding; However since then I changed from that to another place and sadly that api requires sending environment variables which by looks of it SSH.NET does not support (yet).
Well, seveo.net is up again, and I also can not get it to work.
its ssh command can look like this: ssh -R 1111:127.0.0.1:5556 serveo.net
I already use a ForwardedPortRemote(1111, "127.0.0.1", 5556); like this, the problem lies in (I think) that there is no username and also no required password.
That would seem unlikely since the authentication always tries the "none" method first. ForwardedPortRemote has some questionable use of DNS lookups - you could try new ForwardedPortRemote(IPAddress.Loopback, 1111, IPAddress.Loopback, 5556) to rule that out.
Obviously I am just guessing here - "it doesn't work" is not a lot of information to go by.
Yeah sorry, when you connect to the host in a terminal, there is no prompt for a password. When I try to create the sshClient with password as an empty string It throws an "Renci.SshNet.Common.SshAuthenticationException" when I call connect on the client.
If I instead of having an empty password use KeyboardInteractiveAuthenticationMethod or KeyboardInteractiveConnectionInfo. It does not fail when I connect the client and it throws no errors, but still, I do not get the data expected from the shell and by testing the port on the ip I can see that it is still closed.
You may have to use PrivateKeyAuthenticationMethod / PrivateKeyConnectionInfo, but I have no clue how those work.
Ok, please post
- the full error including message and stack trace
- the code you are using (including the code I suggested above)
using SshClient sshClient = new SshClient("serveo.net", "tcp", "");
sshClient.Connect();
Stream shlStream = new MemoryStream();
Shell shell = sshClient.CreateShellNoTerminal(new MemoryStream(), shlStream, new MemoryStream(), 65535);
shell.Start();
var port = new ForwardedPortRemote(0, "127.0.0.1", 5556);
sshClient.AddForwardedPort(port);
port.Start();
await Task.Delay(1000);
int length = (int)shlStream.Length;
byte[] buffer = new byte[length];
shlStream.Read(buffer.AsSpan());
shlStream.Close();
_host = Encoding.UTF8.GetString(buffer);
Exception thrown at sshClient.Connect();
Exception : Renci.SshNet.Common.SshAuthenticationException: 'No suitable authentication method found to complete authentication (publickey,keyboard-interactive).'
This works for me*. The rest is probably a question of firewalls or something
* As in, I see the message from the server - I didn't check the local port
using var connInfo = new KeyboardInteractiveConnectionInfo("serveo.net", "tcp");
// This is unnecessary in this case
connInfo.AuthenticationPrompt += (sender, e) =>
{
Console.WriteLine(e.Instruction);
foreach (AuthenticationPrompt prompt in e.Prompts)
{
Console.WriteLine(prompt.Request);
// TODO prompt.Response = "something"
}
};
using SshClient sshClient = new SshClient(connInfo);
sshClient.Connect();
using ShellStream shellStream = sshClient.CreateShellStreamNoTerminal();
using var port = new ForwardedPortRemote(IPAddress.Loopback, 0, IPAddress.Loopback, 5556);
sshClient.AddForwardedPort(port);
port.Start();
string? line;
while ((line = shellStream.ReadLine(TimeSpan.FromSeconds(5))) != null)
{
Console.WriteLine(line);
}
Console.WriteLine("end");
Console.ReadLine();
port.Stop();
For the avoidance of doubt, this is assuming you've got something already listening on the local port: the client opens a socket to the local endpoint upon receiving a connection from the server side endpoint, and the connection is forwarded from the server socket (through an SSH channel) and on to the local socket. The client does not do any listening on the local port
Yeah I have a separate Tcp server which is listening on port 5556. After copying your shell setup I got text response from the ssh client. In the text response it says that it is forwarding traffic from my local IP on port 0, whilst running the ssh command in the terminal says it is forwarding from serveo.net at a random port
It's not your local IP, it is the loopback interface of the server, but in any case it's probably not the right choice. Try new ForwardedPortRemote(IPAddress.Any, 0, IPAddress.Loopback, 5556);
It is still not getting a random port and it still does not say that it is forwarding from serveo.net, It is also not sending the whole first line that i'm getting when using the terminal about the allocated port and where it is forwarding to. Not really sure what is different from using terminal
I can use a similar service called pinggy and get it to work like so:
using SshClient sshClient = new SshClient("eu.a.pinggy.io", 443, "tcp", "");
sshClient.Connect();
using ShellStream shellStream = sshClient.CreateShellStreamNoTerminal();
using var port = new ForwardedPortRemote(0, "127.0.0.1", 5556);
sshClient.AddForwardedPort(port);
port.Start();
string? line;
while ((line = shellStream.ReadLine(TimeSpan.FromSeconds(5))) != null)
{
Console.WriteLine(line);
}
Console.WriteLine("end");
only difference between the two, is that pinggy has a specific port and a password which is just empty. And with the same ForwardedPortRemote it allocates a port and sends the host and port needed to connect to my server
there also does not seem to be any difference between the three ForwardedPortRemote setups, when using pinggy
ForwardedPortRemote(IPAddress.Any, 0, IPAddress.Loopback, 5556)
ForwardedPortRemote(IPAddress.Loopback, 0, IPAddress.Loopback, 5556)
ForwardedPortRemote(0, "127.0.0.1", 5556)