Skip to content

Instantly share code, notes, and snippets.

@HwDhyeon
Last active March 2, 2020 00:50
Show Gist options
  • Save HwDhyeon/aa3f7f6bda1a56fae52e44b14ac7ad4d to your computer and use it in GitHub Desktop.
Save HwDhyeon/aa3f7f6bda1a56fae52e44b14ac7ad4d to your computer and use it in GitHub Desktop.
paramiko 모듈과 .pem 파일을 이용해 서버에 접속하기
# -*- coding: utf-8 -*-
import paramiko
PRIVATE_KEY = paramiko.RSAKey.from_private_key_file(filename=FILENAME)
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=HOSTNAME, username=USERNAME, pkey=PRIVATE_KEY)
stdin, stdout, stderr = client.exec_command(command='ls -al')
lines = stdout.readlines()
print(''.join(lines))
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment