问题
I'm really really new to python
and ssh
.
I'm trying to write a simple program to open ssh
connection using python
.
I already have paramiko
, but the problem I'm having is this:
Using terminal I use the following command to open my ssh
:
ssh username%hostname@gw.cs.huji.ac.il
Now I don't know what arguments to send to - ssh.connect()
Any ideas?
回答1:
In paramiko documentation there is the following example:
client = SSHClient()
client.load_system_host_keys()
client.connect('ssh.example.com')
stdin, stdout, stderr = client.exec_command('ls -l')
You can also specify the username and password when calling connect(). Here you have the method's signature:
connect(self, hostname, port=22, username=None, password=None,
pkey=None, key_filename=None, timeout=None, allow_agent=True,
look_for_keys=True, compress=False)
回答2:
The docs are pretty clear on this one, have a look and see if you can make sense of it - http://www.lag.net/paramiko/docs/paramiko.SSHClient-class.html#connect
connect(self, hostname, port=22, username=None, password=None, pkey=None, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False)
So for you the command would be
ssh.connect('gw.cs.huji.ac.il', username='username%hostname')
来源:https://stackoverflow.com/questions/11551043/paramiko-ssh-connect-what-arguments-to-send