views:

450

answers:

2
import paramiko

client = paramiko.SSHClient()
client.load_system_host_keys()
ip = '192.168.100.6'
client.connect(ip, username='root', password='mima')
i, o, e = client.exec_command('apt-get install sl -y --force-yes')
print o.read(), e.read()
client.close()

i used this example.. it is working fine but i want after login server1 to login server2 i mean nested ssh . please help me

A: 

You exec the command "ssh" in the client, and not apt-get.

You can't really start a paramiko session on the client as long as your python program isn't there. The software you start using ssh must live on that machine.

Perhaps first scp a copy of your software, and start that using a parameter like -recursive_lvl = 1 ?

extraneon
A: 

can't you call the ssh command from inside of your client.exec_command?
like:

client.exec_command('ssh user@host2 "apt-get install sl -y --force-yes"')
kender
i want see 'freem -m' but how to give password in u r query client.exec_command('ssh user@host2 i want send password also here "apt-get install sl -y --force-yes"') how ?
rajaneesh
i would do the authorization part with keys (public you throw on destination server, into .ssh/authorized_keys, private you keep on the machine you ssh from). It's better and safer then keeping the passwords in your source
kender
import paramikoclient = paramiko.SSHClient()client.load_system_host_keys()ip = 'ip number'client.connect(ip, username='username', password='password')i, o, e = client.exec_command("ssh user@host2 sudo netstat -antp |grep 'CLOSE_WAIT'| ")print o.read(), e.read()client.close()but here problem is it wating for password .. i am new for python .. please tell me how to send password or .ssh/authorized_keys with that
rajaneesh