Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions reference/ssh2/functions/ssh2-auth-pubkey-file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.ssh2-auth-pubkey-file">
<refnamediv>
<refname>ssh2_auth_pubkey_file</refname>
<refpurpose>Authenticate using a public key</refpurpose>
<refpurpose>Authenticate using a public key read from a file</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
Expand All @@ -17,7 +17,7 @@
<methodparam choice="opt"><type>string</type><parameter>passphrase</parameter></methodparam>
</methodsynopsis>
<para>
Authenticate using a public key read from a file.
Authenticate using a public key read from a file.
</para>
</refsect1>

Expand Down Expand Up @@ -48,7 +48,7 @@
The public key file needs to be in OpenSSH's format. It should look something like:
</para>
<para>
ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110
<literal>ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110</literal>
</para>
</listitem>
</varlistentry>
Expand Down Expand Up @@ -118,6 +118,15 @@ if (ssh2_auth_pubkey_file($connection, 'username',
</note>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>ssh2_auth_pubkey</function></member>
</simplelist>
</para>
</refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Expand Down
157 changes: 157 additions & 0 deletions reference/ssh2/functions/ssh2-auth-pubkey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.ssh2-auth-pubkey">
<refnamediv>
<refname>ssh2_auth_pubkey</refname>
<refpurpose>Authenticate using a public key in a variable</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>ssh2_auth_pubkey</methodname>
<methodparam><type>resource</type><parameter>session</parameter></methodparam>
<methodparam><type>string</type><parameter>username</parameter></methodparam>
<methodparam><type>string</type><parameter>pubkey</parameter></methodparam>
<methodparam><type>string</type><parameter>privkey</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>passphrase</parameter></methodparam>
</methodsynopsis>
<para>
Authenticate using a public key in a variable.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>session</parameter></term>
<listitem>
<para>
An SSH connection link identifier, obtained from a call to
<function>ssh2_connect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>username</parameter></term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>pubkey</parameter></term>
<listitem>
<para>
Public key in OpenSSH's format. It should look something like:
</para>
<para>
<literal>ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>privkey</parameter></term>
<listitem>
<para>
Private OpenSSH key. It should begin with:
</para>
<para>
<literal>-----BEGIN RSA PRIVATE KEY-----</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>passphrase</parameter></term>
<listitem>
<para>
If <parameter>privkey</parameter> is encrypted (which it should
be), the <parameter>passphrase</parameter> must be provided.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Authentication using a public key</title>
<programlisting role="php">
<![CDATA[
<?php
$connection = ssh2_connect('shell.example.com', 22, array('hostkey'=>'ssh-rsa'));
$publicKey = file_get_contents('/home/username/.ssh/id_rsa.pub');
$privateKey = file_get_contents('/home/username/.ssh/id_rsa');

if (ssh2_auth_pubkey($connection, 'username',
$publicKey,
$privateKey, 'secret')) {
echo "Public Key Authentication Successful\n";
} else {
die('Public Key Authentication Failed');
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>

<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
The underlying libssh library doesn't support partial auths very cleanly
That is, if you need to supply both a public key and a password it will
appear as if this function has failed. In this particular case a failure
from this call may just mean that auth hasn't been completed yet. You
would need to ignore this failure and continue on and call
<function>ssh2_auth_password</function> in order to complete
authentication.
</para>
</note>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>ssh2_auth_pubkey_file</function></member>
</simplelist>
</para>
</refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
3 changes: 2 additions & 1 deletion reference/ssh2/functions/ssh2-connect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<refname>ssh2_connect</refname>
<refpurpose>Connect to an SSH server</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
Expand Down Expand Up @@ -299,6 +299,7 @@ if (!$connection) die('Connection failed');
<member><function>ssh2_fingerprint</function></member>
<member><function>ssh2_auth_none</function></member>
<member><function>ssh2_auth_password</function></member>
<member><function>ssh2_auth_pubkey</function></member>
<member><function>ssh2_auth_pubkey_file</function></member>
<member><function>ssh2_disconnect</function></member>
</simplelist>
Expand Down
1 change: 1 addition & 0 deletions reference/ssh2/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<function name='ssh2_auth_hostbased_file' from='PECL ssh2 &gt;= 0.9.0'/>
<function name='ssh2_auth_none' from='PECL ssh2 &gt;= 0.9.0'/>
<function name='ssh2_auth_password' from='PECL ssh2 &gt;= 0.9.0'/>
<function name='ssh2_auth_pubkey' from='PECL ssh2 &gt;= 1.4.0'/>
<function name='ssh2_auth_pubkey_file' from='PECL ssh2 &gt;= 0.9.0'/>
<function name='ssh2_connect' from='PECL ssh2 &gt;= 0.9.0'/>
<function name='ssh2_disconnect' from='PECL ssh2 &gt;= 1.0'/>
Expand Down