private key authentication help

Jun 4, 2015 at 8:38 PM
Edited Jun 5, 2015 at 12:45 PM
Attempting to authenticate via username and privatekey only but all examples i can find seem to include in the authenticationMethod[] both a PasswordAuthenticationMethod (which i dont want to use and cant provide the pw for users) and the privateKeyAuthenticationMethod()

if i take out the PasswordAuthenticationMethod i get an exception for no suitable authentication method found.

if i leave it in and pass in no password just "", as i stated previously getting the password from users is not an option the authentication fails. It would seem that the PasswordAuthMethod is being tried and fails and then doesnt try the key method? Is this correct, or does it try both methods?

Again what i need to do is authenticate with a private key and a username. I do not want to pass in a username, password combo.

Is there some way to accomplish this?

here is what i am doing now.
     Renci.SshNet.ConnectionInfo conn = new ConnectionInfo(hostName, port, username, new AuthenticationMethod[]
                new PasswordAuthenticationMethod(username, ""), 
                new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[] { new PrivateKeyFile(privateKeyLocation, "") }),

            using (var sshClient = new SshClient(conn))