phpseclib - 我可以使用用户名、密钥和密码进行连接吗(不是密钥密码)

phpseclib - Can I connect using username, key and password (not a key passphrase)(phpseclib - 我可以使用用户名、密钥和密码进行连接吗(不是密钥密码))
本文介绍了phpseclib - 我可以使用用户名、密钥和密码进行连接吗(不是密钥密码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

抱歉,如果我在文档中遗漏了这一点,但是否可以使用私钥和密码(不是我的私钥的密码)连接到 SFTP 服务器.

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 的解决方案可能支持用户名/密钥和服务器密码身份验证?我在这里很灵活,如果需要可以安装模块.

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.

编辑

感谢到目前为止的帮助...我已经尝试过你提到的 Neubert ,但这似乎不起作用.为了验证连接到服务器需要什么,我在命令行上测试了这个.
sftp key user@ip - 按预期提示输入密码
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".

如果我可以使用密钥和密码进入,我认为对目录和密钥的权限应该没问题.

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');
/
                
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)