PHP Conference Japan 2024

ssh2_auth_hostbased_file

(PECL ssh2 >= 0.9.0)

ssh2_auth_hostbased_file使用公開主機金鑰進行驗證

說明

ssh2_auth_hostbased_file(
    資源 $session,
    字串 $username,
    字串 $hostname,
    字串 $pubkeyfile,
    字串 $privkeyfile,
    字串 $passphrase = ?,
    字串 $local_username = ?
): 布林值

使用從檔案讀取的公開主機金鑰進行驗證。

參數

session

一個 SSH 連線連結識別碼,從呼叫 ssh2_connect() 取得。

username

hostname

pubkeyfile

privkeyfile

passphrase

如果 privkeyfile 已加密(應該如此),則必須提供 passphrase。

local_username

如果省略 local_username,則會使用 username 的值。

回傳值

成功時回傳 true,失敗時回傳 false

範例

範例 #1 使用公開主機金鑰驗證

<?php
$connection
= ssh2_connect('shell.example.com', 22, array('hostkey'=>'ssh-rsa'));

if (
ssh2_auth_hostbased_file($connection, 'remoteusername', 'myhost.example.com',
'/usr/local/etc/hostkey_rsa.pub',
'/usr/local/etc/hostkey_rsa', 'secret',
'localusername')) {
echo
"公開金鑰主機驗證成功\n";
} else {
die(
'公開金鑰主機驗證失敗');
}
?>

注意事項

注意:

ssh2_auth_hostbased_file() 需要 libssh2 >= 0.7 以及 PHP/SSH2 >= 0.7

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top