Dor Shamay
Dor Shamay

Reputation: 435

Escape from SSH host verification on use of Plink session in C# application

I'm creating an application is C#, and I've just encounter a problem with PuTTY's SSH host verification.

When trying to run a Plink session.

When I already ran this specific host already I run into host key caching problem.

Like this:

If you want to carry on connecting just once, without adding the key to the cache, enter "n". If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n)

The idea that I want to write "yes" automatically.

After I've been done some digging on the internet I found a solution to pass:

echo y | plink.exe <the rest of arguments>

But the problem that I'm using the following code:

var processStartInfo = new ProcessStartInfo()
    {
        CreateNoWindow = true,
        FileName = Path.Combine(@"plink.exe"),
        Arguments = string.Format(@"-L {0}:{1}:{2} {3}@{4} -pw ""{5}"" -N -v", {Local forwarding port}, "localhost", {Host port}, "root", ProxyIpAfterPicked, textBox2.Text),
        RedirectStandardError = true,
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false
    };

I've noticed that some peoples examples that pass StreamWriter.Writeline("y"), but it doesn't work either. Is there any way to work with that specific code just to add Arguments to it or something I'm really clueless.

Upvotes: 1

Views: 441

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202118

Upvotes: 1

Related Questions