import paramiko | |
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem") | |
c = paramiko.SSHClient() | |
c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
print "connecting" | |
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k ) | |
print "connected" | |
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ] | |
for command in commands: | |
print "Executing {}".format( command ) | |
stdin , stdout, stderr = c.exec_command(command) | |
print stdout.read() | |
print( "Errors") | |
print stderr.read() | |
c.close() |
This comment has been minimized.
This comment has been minimized.
not working there is my file data |
This comment has been minimized.
This comment has been minimized.
@Ghost0807 - Unclear why your key is not working. The example worked perfectly for me, under Linux |
This comment has been minimized.
This comment has been minimized.
@Ghost0817: your file contains the public key, not the private one … |
This comment has been minimized.
This comment has been minimized.
Hi, This is awesome. Just a correction around the "print "Executing {}".format( command )" statement. Thanks, |
This comment has been minimized.
This comment has been minimized.
A blessing on your house. |
This comment has been minimized.
This comment has been minimized.
I genarate a key with
|
This comment has been minimized.
This comment has been minimized.
@hustcc - use id_rsa, not id_rsa.pub The client uses a private key, not a public one. |
This comment has been minimized.
This comment has been minimized.
Just a note, if you have generated your keys via puttygen and they are in ppk format, it's not going to work, go back to puttygen, load you ppk key and export it as OpenSSH (Conversion -> Export OpenSSH Key) |
This comment has been minimized.
This comment has been minimized.
Thanks it works like a charm! |
This comment has been minimized.
This comment has been minimized.
Hi, how can I fix this? |
This comment has been minimized.
This comment has been minimized.
it worked for me thanks i converted ppk file to OpenSSH key using keygen and it works. Only one note I have for IPV6 address we have to mention the ethernet Interface number following the ipv6 address like "ipv6_address + %ethernet_Interface_Number" for ex. "fe80::217:88ff:fe0d:d1d0%25" |
This comment has been minimized.
This comment has been minimized.
Thanks for example, i try to run this code , i generate key with keygen and export it as OpenSSH key. Private key in the same path of script ... then i copied public key in .ssh in my linux distro and renamed to authorized_key but error occors .... |
This comment has been minimized.
This comment has been minimized.
ok i have solution.
|
This comment has been minimized.
This comment has been minimized.
I'm getting an error while using this example,
|
This comment has been minimized.
This comment has been minimized.
export the PPK file to a PEM format |
This comment has been minimized.
This comment has been minimized.
I can't understand how works this code. I do this steps:
But I get error message which is
What is the thing I'm missing? |
This comment has been minimized.
This comment has been minimized.
Hello guys, I am facing the same issue like @arjunbhoot. I have a working ppk file via putty and filezilla. I tried to puttygen -> Conversions -> Export Open SSH Key and named the file as .pem but does not work. any ideas ?! last version paramiko , python 3.6 |
This comment has been minimized.
This comment has been minimized.
Works for me pretty nicely! "Just a note, if you have generated your keys via puttygen and they are in ppk format, it's not going to work, go back to puttygen, load you ppk key and export it as OpenSSH (Conversion -> Export OpenSSH Key) and save it with .pem file." |
This comment has been minimized.
This comment has been minimized.
:\python27\lib\site-packages\paramiko\client.pyc in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host, passphrase) AuthenticationException: Authentication failed. |
This comment has been minimized.
This comment has been minimized.
Hai guys, import StringIO if any one know the reason let me know |
This comment has been minimized.
This comment has been minimized.
@arjunbhoot did you ever resolve this? |
This comment has been minimized.
This comment has been minimized.
@AymanEG figure this out? |
This comment has been minimized.
This comment has been minimized.
Thank you, sir. |
This comment has been minimized.
This comment has been minimized.
worked for me, after generating the key file in PEM format:
The new default format provided by |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
error: raise TypeError("Expected unicode or bytes, got {!r}".format(s)) use pythn3.7 and lasted paramiko. |
This comment has been minimized.
This comment has been minimized.
Please dont share any kind of keys although shown in comments |
This comment has been minimized.
This comment has been minimized.
Thank you so much for providing this example! |
This comment has been minimized.
This comment has been minimized.
I found this link useful: https://adamdehaven.com/blog/how-to-generate-an-ssh-key-and-add-your-public-key-to-the-server-for-authentication/ |
This comment has been minimized.
This comment has been minimized.
update paramiko to latest version and then it will work even with you new OPENSSH key format |
This comment has been minimized.
This comment has been minimized.
@alexanderfournier make ssh key on computer, authorise on server, use key in program |
This comment has been minimized.
This comment has been minimized.
Error:File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 289, in _read_private_key it worked for me when I created key with type RSA ssh-keygen -m pem -t rsamoreover in python3.8 print statement will not work the way it is mentioned above. Also changed from read to readlines and created a loopxlist = (stdout.readlines())
|
This comment has been minimized.
This comment has been minimized.
Hi, I've converted the file to OpenSSH (with puttygen)
If I use the filename
|
This comment has been minimized.
This comment has been minimized.
Worked perfectly for me. Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Not working for me Traceback (most recent call last): |
This comment has been minimized.
This comment has been minimized.
socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): |
This comment has been minimized.
Thanks.