I'd like to authenticate to an SFTP server using my private key. The private key is not stored in the filesystem.

asked 08 Dec '10, 11:42

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%

edited 08 Dec '10, 12:10

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28


Following code shows how:

// create client and connect 
Sftp client = new Sftp();
client.Connect(hostname);

// instead of loading it from a disk file, load the private key from a byte array
//SshPrivateKey privateKey = new SshPrivateKey("key_rsa.pem", "password");

byte[] privateKeyData = YourMethodForObtainingPrivateKey();    
SshPrivateKey privateKey = new SshPrivateKey(privateKeyData, "password");

// authenticate 
client.Login(username, privateKey);

// ... 
link

answered 08 Dec '10, 11:46

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%

edited 08 Dec '10, 12:11

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×144
×44
×5

Asked: 08 Dec '10, 11:42

Seen: 696 times

Last updated: 30 Mar '11, 17:22