4
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 .

Cœur
  • 37,241
  • 25
  • 195
  • 267
rajaneesh
  • 189
  • 2
  • 5
  • 11

2 Answers2

4

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"')
abyx
  • 69,862
  • 18
  • 95
  • 117
kender
  • 85,663
  • 26
  • 103
  • 145
  • 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 Nov 25 '09 at 12:02
  • 1
    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 Nov 25 '09 at 12:07
  • import paramiko client = 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 Nov 26 '09 at 05:17
0

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
  • 23,575
  • 2
  • 47
  • 51