Using public key authentication

Top  Previous  Next

Public key authentication is a method of authenticating with an SSH server using a private key known only to the user establishing the connection and a public key known to the server. Public key authentication provides an extra level of security above authenticating using only a username and password.

 

Before authenticating using public key authentication you must first create a key pair, install the public key on your server and save the private key locally for use in authentication. For information on creating and installing keys please consult your SSH server documentation. Private keys generated in OpenSSH, Putty, SECSH and VanDyke key formats are supported.

 

Example

 

[C#]

 

// create new SshParameters instance

SshParameters prms = new SshParameters();

 

// ssh hostname

prms.Hostname = "localhost";

 

// ssh port

prms.Port = 22;

 

// ssh username

prms.Username = "test";

 

// ssh password

prms.Password = "testtest";

 

// private key file

prms.SetPrivateKey(privateKeyFile,privateKeyPassword);

 

// create new Ssh instance

Ssh ssh = new Ssh(prms);

 

[VB]

 

' create new SshParameters instance

Dim prms As SshParameters = New SshParameters

 

' ssh hostname

prms.Hostname = "localhost"

 

' ssh port

prms.Port = 22

 

' ssh username

prms.Username = "test"

 

' ssh password

prms.Password = "testtest"

 

' private key file

prms.SetPrivateKey(privateKeyFile,privateKeyPassword)

 

' create new Ssh instance

Dim ssh As Ssh = New Ssh(prms)