3

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.

Shtefan
  • 742
  • 12
  • 14
  • Source on GitHub tells `def userauth_publickey_fromfile(self, username not None, privatekey not None, passphrase='', publickey=None):`. Check your Version you are using. Report this Issue on GitHub. – stovfl Sep 18 '18 at 06:50
  • @ stovfl As explained in the P.S. The argument "privatekey" could mean a file or it could mean bytes. I even thought it could be a string. But at the end I identified that it has to be a file name. Spent some hours on it. The errors, I was getting, were not very informative. They need to change this parameter to something more meaningful. Something like "privatekey_file". Or have appropriate data in the docstring. – Shtefan Sep 18 '18 at 07:09

2 Answers2

1

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=".

Shtefan
  • 742
  • 12
  • 14
1

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

stovfl
  • 14,998
  • 7
  • 24
  • 51