paramiko ssh.connect - what arguments to send?

℡╲_俬逩灬. 提交于 2019-12-07 09:20:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!