0

I'm trying into login into a remote server using paramiko. But it is getting failed with below error

 File "/root/xat-pvt-xat/ssh.py", line 30, in check_aux_host_for_file
    dsakey = paramiko.DSSKey.from_private_key(file_obj=credentials[env]["sftp_pass"])
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/pkey.py", line 217, in from_private_key
    key = cls(file_obj=file_obj, password=password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/dsskey.py", line 52, in __init__
    self._from_private_key(file_obj, password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/dsskey.py", line 232, in _from_private_key
    data = self._read_private_key('DSA', file_obj, password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/pkey.py", line 272, in _read_private_key
    lines = f.readlines()
AttributeError: 'str' object has no attribute 'readlines'


#Implementation

pr_pkey ="""
THE PRIVATE KEY
"""
dsakey = paramiko.DSSKey.from_private_key(pr_pkey)

I tried placing this in a pem file and I tried with below command. dsakey = paramiko.DSSKey.from_private_key_file(open('pr_ssh_key.pem','r'))

Unfortunately that also got failed with below error

   dsakey = paramiko.DSSKey.from_private_key_file(open('pr_ssh_key.pem','r'))
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/pkey.py", line 196, in from_private_key_file
    key = cls(filename=filename, password=password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/dsskey.py", line 55, in __init__
    self._from_private_key_file(filename, password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/dsskey.py", line 228, in _from_private_key_file
    data = self._read_private_key_file('DSA', filename, password)
  File "/root/python3-virtualenv/lib64/python3.6/site-packages/paramiko/pkey.py", line 267, in _read_private_key_file
    with open(filename, 'r') as f:
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper

It would be great if someone could help me to identify what is missing in my implementation. Thanks in advance

Ark
  • 67
  • 7
  • @MartinPrikryl Not working with this one – Ark Jul 23 '21 at 14:55
  • @MartinPrikryl Upon trying that solution i got below error. StringIO is not an attribute of StringIO() – Ark Jul 23 '21 at 16:25
  • Did you see the comment by @ekrekeler? *"In Python 3, import io and use io.StringIO(my_key)"* – Martin Prikryl Jul 23 '21 at 18:41
  • Does this answer your question? [Embedding key as string in Paramiko application](https://stackoverflow.com/questions/27669813/embedding-key-as-string-in-paramiko-application) – Martin Prikryl Jul 27 '21 at 06:40

0 Answers0