Created
July 8, 2022 00:09
-
-
Save nabobalis/4b59ab5a1cc3c502b33fce053f1b1c19 to your computer and use it in GitHub Desktop.
ssh_lmsal
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
import paramiko | |
from sshtunnel import SSHTunnelForwarder | |
with SSHTunnelForwarder( | |
('out.lmsal.com', 22), | |
ssh_username='<USERNAME>', | |
ssh_password="<PASSOWRD>", | |
ssh_pkey="<PATH_TO_SSH_PRIV_KEY>", | |
remote_bind_address=("out.lmsal.com", 22), | |
local_bind_address=('127.0.0.1', 1111) | |
) as tunnel: | |
client = paramiko.SSHClient() | |
client.load_system_host_keys() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(hostname=tunnel.local_bind_host, port=tunnel.local_bind_port, | |
username="<USERNAME>", password="<PASSWORD>") | |
# do some operations with client session | |
stdin, stdout, stderr = client.exec_command("echo abc.txt >> output.txt") | |
print(stdout.channel.recv_exit_status()) # status is 0 | |
client.close() | |
print('FINISH!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment