【问题标题】:How do I get a publickey out of my .pem file如何从我的 .pem 文件中获取公钥
【发布时间】:2021-08-22 17:19:08
【问题描述】:

当我运行我的 python 代码(使用 parmiko 库 python)时,我得到了这个错误:

错误的认证类型;允许的类型:['publickey', 'gssapi-keyex', 'gssapi-with-mic']

我提供的路径是一个 .pem 文件,它是我的服务器密钥。

我如何从这个 .pem 文件中获取公钥,而不必使用 python?

(我用的是mac)

这是我使用的代码:

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()

【问题讨论】:

  • 分享产生错误的运行的 sn-p。
  • 我也在我的终端上使用标准程序进行了尝试,但也没有用。有什么方法可以将我的 pem 文件转换为公钥?
  • ` 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
  • 以下是使用 ssh-keygen 从 .pem 文件中提取公钥的方法:stackoverflow.com/a/38401773/45978

标签: python ssh terminal key pem


【解决方案1】:

Paramiko 似乎没有用于从私钥中提取公钥的 API,但由于您也欢迎非 Python 解决方案,这里是一个命令行版本:

ssh-keygen -y -f myprivatekey

其中myprivatekey 是包含您的私钥的文件(在问题中命名为Insertaddress)。

这会在标准输出上输出公钥。

在 Linux 上测试(命令由包 openssh-client 提供),但也应该在 Mac 上工作。

【讨论】:

    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    相关资源
    最近更新 更多