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
- C#
- 핑거스타일
- Python
- paramiko
- 오류
- JSON
- mysql
- pandas
- 컨테이너
- YOLO
- 프로그래머스
- OpenCV
- 채보
- pytorch
- ubuntu
- C++
- label
- windows forms
- VS Code
- nvidia-smi
- Docker
- 기타 연주
- C
- SSH
- pip
- Selenium
- Visual Studio
- Linux
- Numpy
- error
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python paramiko 프롬프트 상호작용 invoke_shell 본문
Python의 paramiko 모듈을 이용하여 원격 서버에 SSH 접속 후,
passwd와 같이 명령어를 여러 번 주고받아야 할 경우에 간단하게 사용할 수 있는 방법이다.
import paramiko import time def instance_change_password(function_args: dict): ''' args server_ip, user_name, server_password, new_password ''' client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(function_args['server_ip'], username=function_args['user_name'], password=function_args['server_password']) # 상호작용 셸 세션 shell = client.invoke_shell() shell.send('passwd\n') # 프롬프트 대기 while not shell.recv_ready(): time.sleep(0.5) output = shell.recv(65535).decode('utf-8') # 'New password:' 프롬프트를 기다림 if 'New password:' in output: shell.send(f"{function_args['new_password']}\n") print("<New Password Entered>") # 'Retype new password:' 프롬프트를 기다림 while not shell.recv_ready(): time.sleep(0.5) output = shell.recv(65535).decode('utf-8') if 'Retype new password:' in output: shell.send(f"{function_args['new_password']}\n") print("<Re-entered New Password>") client.close()
'Python' 카테고리의 다른 글
Python configparser config file 주석(comment) 유지 (0) | 2025.01.21 |
---|---|
Python open 함수 파일 모드(mode) (3) | 2024.09.03 |
Python logging 모듈 logger 설정(Settings) (0) | 2024.07.10 |
Python 특정 프레임 수 이하 영상 데이터 삭제 (0) | 2024.06.30 |
Python 모든 하위 디렉터리 파일 경로들을 디렉터리 별로 묶기 (1) | 2024.06.04 |