Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh2-python package. Valid parameters for userauth_publickey_fromfile method

Tags:

python

libssh2

Based on docstring this method accepting the following parameters:

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

But official project description has this example:

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

So in this example the second parameter is a public key, but the docstring says it has to be a private key.

Also there are 2 positional arguments in docstring but 4 in the given example.

So what is the correct combination of parameters?

Thanks in advance.

P.S. Moreover it is not clear which format should be the privatekey and the publickey presented in. Should it be like a path to the files or bytes? If it is in bytes, then why the whole function called "_fromfile"? Very confusing.

like image 490
Shtefan Avatar asked Mar 05 '26 23:03

Shtefan


1 Answers

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):  

From the Documentation, only for publickey, the types explained.
For security reasons, a Private Key should never stored inside a python script. You have to read it from a access restriced file storage.

You are right, the Parameters should be explained as in userauth_publickey(...).

Documentation userauth_publickey...
enter image description here

like image 193
stovfl Avatar answered Mar 07 '26 13:03

stovfl