ssh2python包。userauth_publickey_fromfile方法的有效参数

2024-09-27 07:20:07 发布

您现在位置:Python中文网/ 问答频道 /正文

基于docstring,此方法接受以下参数:

Docstring: Session.userauth_publickey_fromfile(self, username, privatekey, passphrase='', publickey=None) Authenticate with public key from file.

但是official project description有这样一个例子:

session.userauth_publickey_fromfile( username, 'my_pkey.pub', 'my_pkey', '')

所以在这个例子中,第二个参数是一个公钥,但是docstring说它必须是一个私钥。在

在docstring中还有2个位置参数,但在给定的示例中有4个。在

那么正确的参数组合是什么呢?在

提前谢谢。在

另外,还不清楚哪种格式应该是privatekey和publickey。它应该像文件或字节的路径吗?如果它是以字节为单位,那么为什么整个函数名为“_fromfile”?非常混乱。在


Tags: 方法self参数字节sessionmyusername例子
2条回答

终于找到了正确的参数组合:

session.userauth_publickey_fromfile(user, '<path to private key file>')

在我的情况下没有密码短语,所以没有提供。 不知道作者为什么这样实现这个函数。“privatekey”是一个强制文件,可以随时从中生成公钥。但它们还有“publickey=”的附加关键字参数。在

Question: it is not clear which format should be the privatekey and the publickey


Source on GitHub tells:

def userauth_publickey_fromfile(self, 
                                username not None, 
                                privatekey not None, 
                                passphrase='', 
                                publickey=None):  

Documentation开始,只有publickeytypes解释了。
出于安全原因,私钥永远不应该存储在python脚本中。 你必须从受访问限制的文件存储中读取。在

您是对的,参数应该解释为userauth_publickey(...)。在

Documentation userauth_publickey...
enter image description here

相关问题 更多 >

    热门问题