This project is read-only.

Autobinding to all local IP addresses

Jan 13, 2010 at 5:22 AM

Awesome project.

I am trying to configure it for using with Amazon EC2 instances. The problem is that IP address is not known in advance.

I propose to add autobinding to all local IP addresses if IP address specified in config.XML is "0.0.0.0"

I added it to my "custom" build and it appears to work fine. Here is the code fix for NSshServiceConfiguration.cs

foreach (var endPoint in endPoints)
            {
                if (endPoint.IPAddress.ToString() == "0.0.0.0")
                {
                    foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
                        foreach (var unicastAddress in i.GetIPProperties().UnicastAddresses)
                            configuration.ListenEndPoints.Add(new IPEndPoint(unicastAddress.Address, endPoint.Port));
                }
                else
                {
                    configuration.ListenEndPoints.Add(new IPEndPoint(endPoint.IPAddress, endPoint.Port));
                }
            }

Developer
Jan 13, 2010 at 5:58 AM

You shouldn't need that code though. If you pass 0.0.0.0 as the IP to bind a socket to Windows automatically binds to all interfaces.

I use 0.0.0.0 in my NSshConfiguration.xml on an Amazon EC2 instance already.

Regards,

Aaron

Jan 13, 2010 at 4:54 PM

Got it... For some reason it was not working for me.

Couple more questions:

- How do you install/start service ? I had to add self-installer to the service code (so it would install on "-install" from command line)

- Do you have an example on how to run powershell command and/or powershell script?

- Is there specific reason to use registry to get installation path? How about

string currentExeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

- Under what account the service should run? "LocalSystem" appears to work fine, but service terminates after EVERY "dir" command that I execute (the command itself executes fine). Generates following log

2010-01-13 07:39:10,398 [8] ERROR NSsh.Server.Service.Program - Unhandled exception in NSsh.
System.InvalidOperationException: Process was not started by this object, so requested information c
annot be determined.
   at System.Diagnostics.Process.EnsureState(State state)
   at System.Diagnostics.Process.get_ExitCode()
   at NSsh.Server.ChannelLayer.Console.BaseProcessConsole.Close() in C:\Develop\NSsh\NSsh.Server\ChannelLayer\Console\BaseProcessConsole.cs:line 107
   at NSsh.Server.ChannelLayer.BaseConsoleChannelConsumer.Close() in C:\Develop\NSsh\NSsh.Server\ChannelLayer\BaseConsoleChannelConsumer.cs:line 48
   at NSsh.Server.ChannelLayer.Channel.<RequestReceived>b__3(Object s, EventArgs e) in C:\Develop\NSsh\NSsh.Server\ChannelLayer\Channel.cs:line 169
   at NSsh.Server.TransportLayer.TransportLayerManager.Disconnect() in C:\Develop\NSsh\NSsh.Server\TransportLayer\TransportLayerManager.cs:line 180
   at NSsh.Server.TransportLayer.TransportLayerManager.Disconnect(DisconnectReason reason) in C:\Develop\NSsh\NSsh.Server\TransportLayer\TransportLayerManager.cs:line 143
   at NSsh.Server.SshSession.Process() in C:\Develop\NSsh\NSsh.Server\SshSession.cs:line 81   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

 

Thank you!

Alex

Jan 13, 2010 at 9:58 PM

Also this line in Service.cs looks like a bug

_service = new NSshService();

Should be changed to

_service = (NSshService)Dependency.Resolve<ISshService>();

Otherwise you endup with 2 instances of NSshService

Developer
Jan 13, 2010 at 10:03 PM
Edited Jan 13, 2010 at 10:19 PM

Yes I encountered that bug as well. I've got the same fix in my local version. I'll give myself a slap on the wrist and commit it pronto.

Update: Actually I do myself a disservice. I checked that fix in for NSsh.Server.Console\Program.cs on 18 Nov 2009 in revision 37630.

Jan 13, 2010 at 10:55 PM

Weird. I downloaded latest version yesterday and did not get the fix...

I finally have NSsh server working as a self-installed service on EC2 - thank you for your product and your responses!

I had to comment out logic that limits number of connection from one IP (because that LINK query throws exceptions "Cannot access disposed socket" under my stress test) and I added Try..Catch to BaseProcessConsole.cs Close() function. Otherwise accessing Process.ExitCode would raise exception from time to time.

But I think that I have a remote console that I actually like! Thank you again.

Do you have advise/examples on executing powershell scripts? I have not tried it yet... But I am looking forward to it :)

Developer
Jan 13, 2010 at 11:02 PM

I think I see the problem with that fix now. I committed to NSsh.Server.Console\Program.cs but I suspect you are using NSsh.Server.Service\Program.cs. I've never used the latter so didn't spot the need for the update there as well.

The connection limit LINQ query is my doing and I've had some issues with it as well and need to get around to fine tuning it.

I can't help on the powershell stuff unfortunately. I don't use powershell for my remote sessions. My need is for a custom VT100 shell rather than giving my users direct access to the OS.

 

Coordinator
Jan 19, 2010 at 10:46 PM

Hi Alex,

There is no good reason why NSsh looks up the registry to find its install location. This code you've posted would work fine:

 

string currentExeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

 

 

I'll make a note to change it over.

 

--Luke

Jul 7, 2011 at 11:28 PM

 

This looks awesome.  I'm just curious though, so I understand what you guys are going for, this server is thee equivalent of the SSH server in Linux, in that the Linux admin gives remote access to whatever he/she wants, right?  So for instance, if I wanted to use it for Secure FTP over SSH2, then I could?  I'm kind of new to this stuff, so forgive me if my question is a stupid one, but I'll tell you though, I'm learning to program in C# via a wonderful book from Wrox, and one of my big things is networking, so if you ever need a hand someday, I hope to be ready to provide hands on here within the time frame of at least a year or less if I can swing it.  By then, I'll probably be on eighty projects at once though knowing me. 

Coordinator
Jul 8, 2011 at 1:18 PM

Yep, that's pretty much the gist of it.

If you do get around to adding any extra features I'll be happy to add them in.

 

Cheers,

 

Luke

Jul 13, 2011 at 9:27 PM

I'll be sure to let you know.  So in the future, are their going to be new features added?  I'm curious because things are looking like they're on a roll, so I applaud you folks.  I do have some questions though.  Is the postsharp version that it listed under dependencies, is that the free or the comercial version?   And is an installer planned for the future?  I saw the WXS file in there.