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 .

2 Answers 2

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"')
Sign up to request clarification or add additional context in comments.

3 Comments

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 ?
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
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
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 ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.