Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
446 B
14
Indexable
Never
def get_private_nlb_ip(ssh_key, instance_ip):

    key_file = StringIO(ssh_key)
    private_key = paramiko.RSAKey.from_private_key(key_file)

    client = paramiko.SSHClient()

    client.connect(hostname=instance_ip, username='ec2-user', pkey=private_key)
    command = 'pwd'
    ssh_stdin, ssh_stdout, ssh_stderr = client.exec_command(command)
    for line in ssh_stdout.readlines():
        print(line)
    client.close()
    key_file.close()