問題描述
抱歉,如果我在文檔中遺漏了這一點,但是否可以使用私鑰和密碼(不是我的私鑰的密碼)連接到 SFTP 服務(wù)器.
Apologies if I have missed this in the documentation but is it possible to connect to an SFTP server with a private key and a password (not a passphrase for my private key).
示例顯示了用戶名/密碼、用戶名/密鑰和用戶名/密鑰/密鑰密碼驗證類型.
The examples show username/password, username/key and username/key/key passphrase authentication types.
通過命令行連接時,我會收到輸入密碼的提示...
When connecting via the command line I would get this prompt for my password...
user@x.x.x.x 的密碼:
user@x.x.x.x's password:
希望這個庫可以處理這個問題嗎?
Hopefully this library can handle this?
否則,是否還有其他基于 PHP 的解決方案可能支持用戶名/密鑰和服務(wù)器密碼身份驗證?我在這里很靈活,如果需要可以安裝模塊.
Otherwise are there any other PHP based solutions that might support username/key and server password authentication? I'm quite flexible here and can install modules if need be.
編輯
感謝到目前為止的幫助...我已經(jīng)嘗試過你提到的 Neubert ,但這似乎不起作用.為了驗證連接到服務(wù)器需要什么,我在命令行上測試了這個.sftp key user@ip
- 按預(yù)期提示輸入密碼sftp user@ip
- 提示輸入密碼,但輸入正確后告訴我已通過身份驗證并部分成功".
Thanks for the help so far...
I had tried what you mentioned Neubert but this didn't seem to work.
And to verify what is necessary to connect to the server I tested this on the command line.
sftp key user@ip
- Prompted for password as expected
sftp user@ip
- Prompted for password but when entered correctly told I am "authenticated with partial success".
如果我可以使用密鑰和密碼進入,我認為對目錄和密鑰的權(quán)限應(yīng)該沒問題.
I think the permission on directories and keys should be fine if I can get in using key and then password.
我開始認為這個庫不支持我需要的東西.
I am starting to think this library doesn't support what I need.
推薦答案
phpseclib 支持多因素認證.以下是如何操作的示例:
phpseclib supports multi factor authentication. Here's an example of how to do it:
<?php
include('Net/SSH2.php');
include('Crypt/RSA.php')
$rsa = new Crypt_RSA();
$rsa->loadKey(file_get_contents('/path/to/key.pem'));
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'pass1', $rsa)) {
exit('Login failed');
}
// this does the same thing as the above
//if (!$ssh->login($username, 'pass1') && !$ssh->login('username', $rsa)) {
// exit('Login failed');
/
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!