Home > Net >  Getting "Pseudo-terminal will not be allocated because stdin is not a terminal" when execu
Getting "Pseudo-terminal will not be allocated because stdin is not a terminal" when execu

Time:12-16

I have some solution based on SSH.NET library.
Now the department wants to monitor SSH sessions.
So they ask us to connect to something like 'proxy' SSH server and pass remote command to it to get redirected to destination machine.

Basically the question is how to send parameter to the session the way PuTTY does, when you specify it in the "Remote command" field: enter image description here using ssh.net ?

I have tried this:

var pk = new PrivateKeyFile("C:\\xxx.ppk");        
client = new SshClient("x.x.x.x","login",pk);
client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(10);
client.Connect();
SshCommand x = client.CreateCommand("user@server1");
var response = x.Execute();
shells = client.CreateShellStream("vt100", 250, 250, 800, 160, 512);

But when running it like this I get an error:

Error = "Pseudo-terminal will not be allocated because stdin is not a terminal.\r\nPermission denied, please try again.\r\nPermission denied, please try again.\r\nReceived disconnect from x.x.x.x port 22:2: Too many authentication failures for y\r\nDisconne...

If I do it from PuTTY and send user@server1 in "Remote command" then i get immediately asked for password for passwords of user@server1.

CodePudding user response:

The underling API of PuTTY "Remote command" is SSH "exec" channel.

In SSH.NET the API for "exec" channel is indeed the SshClient.CreateCommand/SshClient.RunCommand:
How to run commands on SSH server in C#?

But while PuTTY (being interactive SSH terminal) allocates pseudo terminal for the session by default, the SSH.NET SshClient.CreateCommand (being intended for command automation and not for an interactive use) does not. Your command seems to be intended for an interactive use, so it cannot run in such session.

  • Check if you command has an option/switch/whatever to make it run in a session without pseudo terminal.
  • If there's no such option, you will have to implement alternative to the standard SshClient.CreateCommand/SshClient.RunCommand that allocates the pseudo-terminal by calling ChannelSession.SendPseudoTerminalRequest.
  • Related