using Rebex.Net;

Welcome to using Rebex.Net; Sign in | Help
in Search

Using Rebex.Net

News and announcements about Rebex.NET components

New component: Rebex SSH Shell for .NET - Secure shell and terminal emulation

A new component has just been released: Rebex SSH Shell for .NET.

Rebex SSH Shell component is an SSH shell and terminal emulation library for .NET languages (such as C# or VB.NET). It makes it easy to execute commands on Unix/Windows SSH servers or add terminal emulation capabilities to your applications. All popular Linux and Windows SSH servers are supported. Most common shells are supported as well.

Features include:

  • Remote command execution over SSH channel.
  • Remote SSH shell.
  • Terminal emulation (Windows Forms control and virtual terminal).
  • Terminal session recording and replay
  • Username/password and public key authentication
  • Lot of samples in C# and VB.NET including WinForm SSH client.
  • Easy-to-follow tutorial for a quick start.
  • Includes Rebex Security component with support for signature/verification, encryption/decryption, etc.
  • Complete C# source code is optionally available.
  • And more...

Additionally, we have added Rebex SSH Pack to our portfolio - this contains both SFTP (file transfer over SSH) and SSH Shell components in a single pack.

See also: SSH Shell component homepage | Download trial | Pricing from $349

Published Monday, July 28, 2008 3:00 PM by Lukas Pokorny

Comments

 

Ho Jae Lee said:

SimpleShell

prompt

su -

standard in must be a tty

why not execute?

October 2, 2008 4:24 AM
 

Lukas Pokorny said:

Hello, "su" is a very special command and it won't run from a terminal-less shell by design because it refuses to take password when it is not running from a full terminal. In fact, it is not intended to be run by automated scripts, which is actually what the SimpleShell is all about - programatic automated scripting. The "sudo" command is the recommended workaround for these purposes. Also, this particular sample can't be used to start commands that require user interaction - and it states this when it is started.

Check out the following forums for more information:

http://www.ae.iitm.ac.in/pipermail/ilugc/2002-September/000726.html

http://www.linuxforums.org/forum/linux-programming-scripting/62738-get-password-through-shell-script.html

http://forums.sun.com/thread.jspa?messageID=4209908

What other options are there?

1) Use "sudo" command instead (recommended)

2) Use our VirtualTerminal class to do the work (bit more complicated than Shell class for this purpose, but it can be done)

3) Try to use the Shell command in Prompt-based mode - this makes "su" possible, but sending passwords is not supported by our API at the moment (will be there in the next release soon), so for now, we have to resort to undocumented functionality for this. See the code below:

In the SimpleShell sample, instead of this:

// start the shell in prompt-detection mode

Shell shell = ssh.StartShell(ShellMode.WellKnownShell);

Use this:

// start the shell in prompt-detection mode

Shell shell = ssh.StartShell(ShellMode.Prompt);

// set the prompt string of the user's shell

// (this line must be modified to match the actual prompt!)

shell.Prompt = "user01@server01:~$ ";

// run the 'su' command

shell.SendCommand("su");

// wait until the shell asks for password

string result = shell.ReadAll("Password: ");

Console.WriteLine(result);

// if it has not asked for password, throw an exception

if (!result.EndsWith("Password: "))

throw new ApplicationException("Unexpected su response.");

// ask the user for password

string password = Console.ReadLine();

// send the password to the server using internal functionality

// (there will be a public method for this in the next release!)

typeof(Shell).InvokeMember(

"SendData",

System.Reflection.BindingFlags.Instance |

System.Reflection.BindingFlags.NonPublic |

System.Reflection.BindingFlags.InvokeMethod,

null,

shell,

new object[] { password }

);

shell.SendCommand("");

// set the prompt string of the new user's shell

// (this line must be modified to match the actual prompt!)

shell.Prompt = "server01:/home/user01# ";

Console.WriteLine(shell.ReadAll());

This will start the "su" command at the beginning and ask for password.

Please let me know if you prefer VB.NET!

October 3, 2008 5:40 PM
New Comments to this post are disabled
Powered by Community Server (Personal Edition), by Telligent Systems