Python |
||||||||||
Python - SSH
NOTE : The Python scrip in this note ran on Windows 10, Python 3.9.1 and the ssh server that the script is connecting to was running on two different types : fedora 33 on a separate PC and Ubuntu 20.04.1 running on a Virtual Box on the same PC.
Installation of paramiko
To run the examples in this page, you need to install the package : paramiko as shown below
Basic Connection
NOTE : For IPv6 connection, you can set the server IP in the format as shown below.
pyTTY.connect('2607:fea8:e260:a340:74ad:72ca:da40:815d', username='jaeku', password='********')
Command for change directory
For most of commands, you just need to put a string of command as shown in the above example, but in case of any command that use change directory ('cd'), you need to put the command 'cd' and any follow-up commands into a single command string as shown below.
Troubleshoot Tips :
In terms of scripting, the examples shown above would work without much difficulties. If you still have issues with the connection, it is likely to be related to sshd setting on server side. My recommendation is to try with PuTTY and check if you can connect to the server (ssh destination) first. If you have any issues with PuTTY due to server side issue, refer to my notes on ssh troubleshooting.
|
||||||||||