Authentication with PPK key in SSH.NET

SSH.NET does not support .ppk key files. You have to use PuTTYgen to convert the .ppk key to OpenSSH format. See How to convert SSH keypairs generated using PuTTYgen (Windows) into key-pairs used by ssh-agent and Keychain (Linux). Original answer, before the question was edited: You are using multifactor private key and keyboard interactive authentication … Read more

Providing subcommands to a command (sudo/su) executed with SSH.NET SshClient.CreateShellStream

Just write the “commands” to the StreamWriter. writer.WriteLine(“sudo su – wwabc11”); writer.WriteLine(“whoami”); // etc See also C# send Ctrl+Y over SSH.NET. Though note that using CreateShellStream (“shell” channel) is not the correct way to automate a commands execution. You should use CreateCommand/RunCommand (“exec” channel). Though SSH.NET limited API to the “exec” channel does not support … Read more

Providing input/subcommands to a command (cli) executed with SSH.NET SshClient.RunCommand

AFAIK, cli is a kind of a shell/interactive program. So I assume you have tried to do something like: client.RunCommand(“cli”); client.RunCommand(“some cli subcommand”); That’s wrong. cli will keep waiting for subcommands and never exit, until you explicitly close it with a respective command (like exit). And after it exits, the server will try to execute … Read more

How to run commands on SSH server in C#?

You could try https://github.com/sshnet/SSH.NET. With this you wouldn’t need putty or a window at all. You can get the responses too. It would look sth. like this. SshClient sshclient = new SshClient(“172.0.0.1”, userName, password); sshclient.Connect(); SshCommand sc= sshclient .CreateCommand(“Your Commands here”); sc.Execute(); string answer = sc.Result; Edit: Another approach would be to use a shellstream. … Read more