Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paramiko ssh.connect - what arguments to send?

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%[email protected]

Now I don't know what arguments to send to - ssh.connect()

Any ideas?

like image 610
oopsi Avatar asked Jul 18 '12 22:07

oopsi


People also ask

How do I connect to my Paramiko server?

A Paramiko SSH Example: Connect to Your Server Using a Password. This section shows you how to authenticate to a remote server with a username and password. To begin, create a new file named first_experiment.py and add the contents of the example file. Ensure that you update the file with your own Linode's details.

What is Paramiko SSHClient ()?

SSHClient. A high-level representation of a session with an SSH server. This class wraps Transport , Channel , and SFTPClient to take care of most aspects of authenticating and opening channels. A typical use case is: client = SSHClient() client.

What is Paramiko connection?

Paramiko is a pure-Python [1] (2.7, 3.4+) implementation of the SSHv2 protocol [2], providing both client and server functionality.


2 Answers

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)
like image 68
betabandido Avatar answered Oct 05 '22 17:10

betabandido


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')
like image 37
mjallday Avatar answered Oct 05 '22 16:10

mjallday