pythonlibssh2

ssh2-python package. Valid parameters for userauth_publickey_fromfile method


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.


Solution

  • Have finally found the right combination of the parameters:

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

    No passphrase in my case, so it is not provided. Do not know why the authors implemented this function such way. The "privatekey" is a mandatory filed and public key can be generated from it any time. But they also have additional keyword argument for "publickey=".