The way to use SSH in your Python utility


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

Possibility 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)

Possibility 2 – Utilizing the subprocess module

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

Possibility 3 – Utilizing the subprocess module

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

Leave a Reply