March 2019
Beginner
490 pages
12h 40m
English
Now that we are connected to the remote host with paramiko, we can run commands on the remote host using this connection. To connect, we can simply call the connect() method, along with the target hostname and the SSH login credentials. To run any command on the target host, we need to invoke the exec_command() method by passing the command as its argument:
ssh_client.connect(hostname, port, username, password)stdin, stdout, stderr = ssh_client.exec_command(cmd) for line in stdout.readlines(): print(line.strip())ssh.close()
The following code listing shows how to do an SSH login to a target host and then run the command the user introduced in the prompt. You can find the following code in the ssh_execute_command.py ...
Read now
Unlock full access