如何使用Python使用pem密钥连接到EC2实例(不使用paramiko模块)

时间:2018-02-12 04:56:06

标签: python linux amazon-web-services amazon-ec2 ssh

如何在不使用paramiko模块的情况下使用python使用pem键登录EC2实例,以下代码与paramiko有效,但我需要没有paramiko。

def ssh_login(self):

    try:
        cert = paramiko.RSAKey.from_private_key_file("key.pem")
        c = paramiko.SSHClient()
        c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        print "connecting..."
        c.connect( hostname = "10.0.0.0", username = "example", pkey = cert )
        print "connected!!!"
        stdin, stdout, stderr = c.exec_command('ls')
        print stdout.readlines()
        c.close()

    except:
        print("Connection Failed!!!")

0 个答案:

没有答案