0

When I ran my python code (using parmiko library python) I got this error:

Bad authentication type; allowed types: ['publickey', 'gssapi-keyex', 'gssapi-with-mic']

The path I supplied was to a .pem file which was my key to the server.

How do I get a public key out of this .pem file not necessarily using python?

(I am using a mac)

Here is the code I used:

import paramiko

def file_move(): 
    k = paramiko.RSAKey.from_private_key_file("Insertadress") 
    c = paramiko.SSHClient()
    c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    print ("connecting...") 
    c.connect(hostname = "inserthostname", username = None, password = "insert pw" ,pkey = k) 
    print ("connected!!!") 
    stdin, stdout, stderr = c.exec_command('ls')
    c.close() 
    
file_move()
Flavia Giammarino
  • 7,987
  • 11
  • 30
  • 40
Adi Krish
  • 13
  • 2
  • Share the snippet of what was run that produced the error. – abhishek phukan Jun 04 '21 at 17:05
  • I tried it on my terminal as well using the standard procedures and that didn’t work either. Is there any way to convert my pem file to a public key? – Adi Krish Jun 04 '21 at 17:51
  • ` import paramiko def file_move(): k = paramiko.RSAKey.from_private_key_file("Insertadress") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print ("connecting...") c.connect(hostname = "inserthostname", username = None, password = "insert pw" ,pkey = k) print ("connected!!!") stdin, stdout, stderr = c.exec_command('ls') c.close() file_move() ` @abhishekphukan – Adi Krish Jun 04 '21 at 17:58
  • Here's how to extract the public key from the .pem file using ssh-keygen: https://stackoverflow.com/a/38401773/45978 – Joe Casadonte Jun 04 '21 at 23:54

1 Answers1

1

Paramiko does not seem to have an API for extracting the public key from a private key, but since you are welcoming non-Python solutions too, here is a command line version:

ssh-keygen -y -f myprivatekey

where myprivatekey is the file containing your private key (named Insertaddress in the question).

This outputs the public key on standard output.

Tested on Linux (where the command is provided by the package openssh-client), but should work on a Mac too.

Adrian W
  • 4,563
  • 11
  • 38
  • 52