Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Visual Studio
- Selenium
- ubuntu
- 핑거스타일
- mysql
- VS Code
- pytorch
- SSH
- Linux
- label
- YOLO
- C#
- 컨테이너
- 기타 연주
- JSON
- paramiko
- Python
- 프로그래머스
- C++
- Docker
- error
- pip
- 오류
- windows forms
- 채보
- C
- pandas
- OpenCV
- nvidia-smi
- Numpy
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python SSH Client 원격 연결 (Paramiko) 본문
Python에서 Paramiko를 이용한 간략한 SSH Client 원격 연결 방법이다.
설치
pip install paramiko
사용
Client — Paramiko documentation
Client SSH client & key policies class paramiko.client.SSHClient A high-level representation of a session with an SSH server. This class wraps Transport, Channel, and SFTPClient to take care of most aspects of authenticating and opening channels. A typical
docs.paramiko.org
import paramiko import time cli = paramiko.SSHClient() # set_missing_host_key_policy: 알려진 호스트 키 없이 서버에 연결할 때 사용할 정책 설정 # AutoAddPolicy: 알려지지 않은 서버에 연결할 때 키를 추가하고 저장 cli.set_missing_host_key_policy(paramiko.AutoAddPolicy) # hostname에는 domain 주소 또는 IP 주소를 입력한다. cli.connect("hostname", port=22, username="username", password="password") timeout = 3 stdin, stdout, stderr = cli.exec_command("ls -al") endtime = time.time() + timeout # timeout 시간동안 응답이 없을 경우 while not stdout.channel.eof_received: time.sleep(1) if time.time() > endtime: stdout.channel.close() break lines = stdout.readlines() print(''.join(lines)) cli.close()
'Python' 카테고리의 다른 글
Python stacktrace 출력 traceback module (0) | 2023.04.09 |
---|---|
Python pymysql cursor DB 값 변경 인식 불가 (0) | 2023.04.01 |
Python 깊은 복사, 얕은 복사 (Shallow Copy, Deep Copy) (0) | 2023.02.12 |
Python 객체 파일로 저장, 직렬화 (pickle) (0) | 2023.01.28 |
Python 변수 타입 선언 (0) | 2023.01.28 |