| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 | <?xml version="1.0" encoding="utf-8"?><topic id="c233e412-0ea1-422f-8337-e5d1231b71e5" revisionNumber="1">  <developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">    <introduction>      <para>        This topic describes hot to connect to the remote host using private key file.        <!--        To connect to remote server using private key you need to provide <codeEntityReference>T:Renci.SshNet.PrivateKeyFile</codeEntityReference> object which points to file that contains private key information.-->      </para>      <list class="bullet">        <listItem>          <para>            <link xlink:href="#PrivateKeyGenerationSection">Private Key file generation.</link>          </para>        </listItem>        <listItem>          <para>            <link xlink:href="#PrivateKeyExamplesSection">Private Key file examples.</link>          </para>        </listItem>        <listItem>          <para>            <link xlink:href="#CreatePrivateKeyFileInstanceSection">Create PrivateKeyFile instance.</link>          </para>        </listItem>        <listItem>          <para>            <link xlink:href="#UsePrivateKeyFileInstanceSection">Using PrivateKeyFile instance.</link>          </para>        </listItem>        <listItem>          <para>            <link xlink:href="#MultiplePrivateKeyFilesSection">Using multiple private key files.</link>          </para>        </listItem>      </list>    </introduction>    <section address="PrivateKeyGenerationSection">      <title>Private Key file generation</title>      <content>        <para>          Before using private key for authentication you need to create one and configure remote host to accept it.          Typically it can be done by executing following command on the remote host.        </para>        <code language="text" title="Private key generation example">          ssh-keygen -t rsa        </code>      </content>    </section>    <section address="PrivateKeyExamplesSection">      <title>Private Key file examples</title>      <content>        <para>          To use private key for authentication, private key must be generated. Typecally it can be done un remote host by issue <command>ssh-keygen -t rsa</command> command.          Below are some private key examples:        </para>        <code language="text" title="Private RSA key example">            <![CDATA[-----BEGIN RSA PRIVATE KEY-----MIIEoQIBAAKCAQEAuT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U/Pe3rDdcLSgvD2h2dpvQZPo2L3l0/WQx2t2o78H3fuWftfAcB2Iav6nIJNNZn75BvXaug4E1ej5NUaJdYtL+Q/3UtrqR1s6opwVabWWTtElPvGmhzboodwk30en8CgYAyuPzNCfGdm00lMZ8JPH7pTwaBDq4xdrDM9FgHUCnaE0FlXP0uTgT2J6nSQKijtPI75JadfhgvL1E+vTLmX2wViBU45XvcrlZ92Vlr0nBLwbgnUB1otIzauyD49AuIsFegxSWcZ8QCJmKIMlouir0X1FyR3Apfzv6Qfio+kyNHvwKBgQCtwxojkzUSfV3zDt6bYSLBzgXgo/Zr9lS+gSggP72DzINmW2gbA0fkM2ZuJltcfakKv4gVX/1zooz+7t+4bj6dqt+bl7hYz0VnTSDZGuo5LKDif/4gSGrdblC2QLTuX2HjWCZdsue7mRwL7cXR4zlIoE99+Ryhdxvc5wHSfYr/JA==-----END RSA PRIVATE KEY-----]]>          </code>      </content>    </section>    <section address="CreatePrivateKeyFileInstanceSection">      <title>Create PrivateKeyFile instance</title>      <content>        <para>          To specify private key you need to intsantiate <codeEntityReference>T:Renci.SshNet.PrivateKeyFile</codeEntityReference> object.          Some private key require passphrase to be specified.          <alert class="note">            <para>              If private key requires a passphrase but it was not specified then <codeEntityReference>T:Renci.SshNet.Common.SshPassPhraseNullOrEmptyException</codeEntityReference> exception will be thrown.            </para>          </alert>        </para>        <code language="cs" title="Create PrivateKeyFile without providing passphrase">            var keyFile = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"));          </code>          <code language="cs" title="Create PrivateKeyFile by providing passphrase">            var keyFile = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"), "tester")          </code>      </content>    </section>    <section address="UsePrivateKeyFileInstanceSection">      <title>Using PrivateKeyFile instance</title>      <content>        <para>          You can pass <codeEntityReference>T:Renci.SshNet.PrivateKeyFile</codeEntityReference> object to client constructor or when creating <codeEntityReference>T:Renci.SshNet.PrivateKeyConnectionInfo</codeEntityReference> object.        </para>        <code language="cs" title="Provide PrivateKeyFile instance to PrivateKeyConnectionInfo example">            var keyFile = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"));            var connectionInfo = new PrivateKeyConnectionInfo("server", 22, "tester", keyFile);          </code>          <code language="cs" title="Provide PrivateKeyFile instance to SshClient example">            var keyFile = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"), "tester")            using (var client = new SshClient("host", "username", keyFile))            {            }          </code>      </content>    </section>    <section address="MultiplePrivateKeyFilesSection">      <title>Using multiple private key files</title>      <content>        <para>          In some scenarious you might want to provide multiple private key to authenticate user. In this case you create PrivateKeyFile as described <link xlink:href="#CreatePrivateKeyFileInstanceSection">here</link> and then pass those file to either client or <codeEntityReference>T:Renci.SshNet.PrivateKeyConnectionInfo</codeEntityReference> constructor.        </para>        <code language="cs" title="Provide multiple PrivateKeyFile instances example">            var keyFile1 = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key1.txt"));            var keyFile2 = new PrivateKeyFile(File.OpenRead(@"rsa_pass_key2.txt"));            var connectionInfo = new PrivateKeyConnectionInfo("server", 22, "tester", keyFile1, keyFile2);          </code>      </content>    </section>    <!--    <content>      <para>            Some private key are encrypted using passphrase. You can specify passphrase by creating private key using <codeEntityReference qualifyHint="true" autoUpgrade="true">M:Renci.SshNet.PrivateKeyFile.#ctor(Stream, String)</codeEntityReference> or <codeEntityReference qualifyHint="true" autoUpgrade="true">M:Renci.SshNet.PrivateKeyFile.#ctor(System.String, System.String)</codeEntityReference> constructors.      Test <codeEntityReference qualifyHint="true" autoUpgrade="true">M:Renci.SshNet.PrivateKeyFile.#ctor</codeEntityReference>            </para>      <codeExample>        <list class="ordered">          <listItem>            <para>Providing private key directly in the client constructor</para>            <code language="cs">              using (var client = new SshClient("host", "username", new PrivateKeyFile(File.OpenRead(@"private.key"))))              {              client.Connect();              client.Disconnect();              }            </code>          </listItem>          <listItem>            <para>Providing private key and passphrase directly in the client constructor</para>            <code language="cs">              using (var client = new SshClient("host", "username", new PrivateKeyFile(File.OpenRead(@"private.key"), "passphrase")))              {              client.Connect();              client.Disconnect();              }            </code>          </listItem>          <listItem>            <para>Providing private key and passphrase directly using <codeEntityReference>T:Renci.SshNet.PrivateKeyConnectionInfo</codeEntityReference> object.</para>            <code language="cs">              var connectionInfo = new PrivateKeyConnectionInfo("host", 1234, "username", new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"), "tester"));              using (var client = new SshClient(connectionInfo))              {              client.Connect();              client.Disconnect();              }            </code>          </listItem>        </list>      </codeExample>    </content>-->    <relatedTopics>      <codeEntityReference>T:Renci.SshNet.PrivateKeyConnectionInfo</codeEntityReference>      <codeEntityReference>T:Renci.SshNet.SshClient</codeEntityReference>      <codeEntityReference>M:Renci.SshNet.SshBaseClient.Connect()</codeEntityReference>    </relatedTopics>  </developerConceptualDocument></topic>
 |