Last active
March 2, 2020 00:50
-
-
Save HwDhyeon/aa3f7f6bda1a56fae52e44b14ac7ad4d to your computer and use it in GitHub Desktop.
paramiko 모듈과 .pem 파일을 이용해 서버에 접속하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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