I need to connect to a server with SSH to download files. I have Ubuntu and I've set up SSH in the standard way: I have a ssh_config
file in .ssh
which defines a host entry (say host_key
) for the server address (Hostname.com
) and username, and I've set up an RSA key. So when I try to log into SSH from the command line or bash, I just need to use ssh host_key
I would like to do this in Python. The standard solutions seems to be to use Paramiko to set up the connection. I tried this:
from paramiko import SSHClient
from scp import SCPClient
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect('host_key')
scp = SCPClient(ssh.get_transport())
# etc...
However, it always seems to hang and time out on ssh.connect('host_key')
. Even when I try to include the username and password: ssh.connect('host_key', username='usrnm', password='pswd')
.
Are my host keys not loading properly? And would this take care of the RSA keys as well?
It only works if I use the whole Hostname.com
with username and typed-out password. Which is maybe a bit insecure.