phpseclib-我可以使用用户名,密钥和密码(而不是密钥密码)进行连接 [英] phpseclib - Can I connect using username, key and password (not a key passphrase)

查看:205
本文介绍了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');
//}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>

但是要记住一些事情:许多人将受密码保护的私钥混淆为多因素(密码和公钥),而实际上却并非如此.至少就SSH而言并非如此.

Something to keep in mind, however: a lot of people confuse password protected private keys as being multi factor (password and public key) when in fact it is not. At least not in-so-far as SSH is concerned.

这篇关于phpseclib-我可以使用用户名,密钥和密码(而不是密钥密码)进行连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆