public static void publickeyAuth() { Chilkat.Ssh ssh = new Chilkat.Ssh(); // Any string automatically begins a fully-functional 30-day trial. bool success = ssh.UnlockComponent("Anything for 30-day trial"); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } // Set some timeouts, in milliseconds: ssh.ConnectTimeoutMs = 5000; ssh.IdleTimeoutMs = 15000; // Connect to the SSH server. // The standard SSH port = 22 // The hostname may be a hostname or IP address. int port; string hostname; hostname = "172.24.16.155"; port = 22; success = ssh.Connect(hostname, port); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } Chilkat.SshKey key = new Chilkat.SshKey(); // Read the PEM file into a string variable: // (This does not load the PEM file into the key. The LoadText // method is a convenience method for loading the full contents of ANY text // file into a string variable.) string privKey = key.LoadText("private.ppk"); if (key.LastMethodSuccess != true) { Console.WriteLine(key.LastErrorText); return; } // Load a private key from a PEM string: // (Private keys may be loaded from OpenSSH and Putty formats. // Both encrypted and unencrypted private key file formats // are supported. This example loads an unencrypted private // key in OpenSSH format. PuTTY keys typically use the .ppk // file extension, while OpenSSH keys use the PEM format. // (For PuTTY keys, call FromPuttyPrivateKey instead.) success = key.FromOpenSshPrivateKey(privKey); if (success != true) { Console.WriteLine(key.LastErrorText); return; } // Authenticate with the SSH server using the login and // private key. (The corresponding public key should've // been installed on the SSH server beforehand.) success = ssh.AuthenticatePk("myLogin", key); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } Console.WriteLine(ssh.LastErrorText); Console.WriteLine("Public-Key Authentication Successful!"); }
public static void puttykeyAuth(int serverPort) { Chilkat.Ssh ssh = new Chilkat.Ssh(); bool success = ssh.UnlockComponent("Anything for 30-day trial."); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } // Load a .ppk PuTTY private key. Chilkat.SshKey puttyKey = new Chilkat.SshKey(); string ppkText = puttyKey.LoadText("private_key.ppk"); // The ppkText contains this content: // PuTTY-User-Key-File-2: ssh-rsa // Encryption: aes256-cbc // Comment: rsa-key-20170126 // Public-Lines: 6 // AAA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90PzdBom4ikIuf7sMwtElrHHLuYfcXJQYLp // G5jBmqDgnirosVPEBIxlxFzz/HCRmdU+tsYg46gqI4R5UpKUe8WSaJoZkDGsrqhm // e+1SJaBuafR4v2bx/bV414Hg7LGQosK2S3crxH4UgZl+g02vWznZfBH+9CmHvKDR // AxfcKOTzsaILKJtQPV81lmJ45sARYMcB5jMiE4kBg56hiXouChsvKkm55WVcW1E+ // Private-MAC: 17512c9f7582c1d9c3ae2b01b4d67a6b1dbd1d0e // "secret" is the actual password for the above PPK. puttyKey.Password = "******"; success = puttyKey.FromPuttyPrivateKey(ppkText); if (success != true) { Console.WriteLine(puttyKey.LastErrorText); return; } string sshHostname = "172.24.16.155"; //string sshHostname = "172.24.19.59"; int sshPort = 22; // Connect to an SSH server success = ssh.Connect(sshHostname, sshPort); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } // Authenticate with the SSH server using a username + private key. // (The private key serves as the password. The username identifies // the SSH user account on the server.) success = ssh.AuthenticatePk("harinath", puttyKey); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } Console.WriteLine("OK, the connection and authentication with the SSH server is completed."); }