Tuesday, March 14, 2023
HomeSoftware EngineeringThe best way to use SSH in your Python software

The best way to use SSH in your Python software


If you might want to make an SSH connection and points instructions over SSH utilizing your Python software, then you are able to do the next:

Choice 1 – Utilizing the paramiko library

ssh = paramiko.SSHClient()
ssh.join(server, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)

Choice 2 – Utilizing the subprocess module

subprocess.check_output(['ssh', 'my_server', 'echo /*/'])

Choice 3 – Utilizing the subprocess module

subprocess.Popen("ssh {consumer}@{host} {cmd}".format(consumer=consumer, host=host, cmd='ls -l'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).talk()
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments