Seite 1 von 1

paramiko ssh login

Verfasst: Mittwoch 6. März 2013, 11:15
von bob1704
Hallo,
habe folgendes Problem...

Mittels Paramiko stelle ich eine Verbindung zu einem Server her:

Code: Alles auswählen

ssh = paramiko.SSHClient()    
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(<my connection details>) 
Im Anschluss daran, möchte ich mich gerne von diesem Server aus, auf einer weiterem PC einloggen.
Hat einer eine Idde, wie man das ganze am Besten umsetzten kann?

Habe es bereits über das channel Modul porbiert, allerdings bislang ohne Erfolg.

Danke und Gruß

Re: paramiko ssh login

Verfasst: Freitag 8. März 2013, 07:39
von bob1704
Problem gelöst !

Fürs Archiv :

Code: Alles auswählen

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('first.com', username='luser', password='secret')

chan = ssh.invoke_shell()

# Ssh and wait for the password prompt.
chan.send('ssh second.com\n')
buff = ''
while not buff.endswith('\'s password: '):
    resp = chan.recv(9999)
    buff += resp

# Send the password and wait for a prompt.
chan.send('secret\n')
buff = ''
while not buff.endswith('some-prompt$ '):
    resp = chan.recv(9999)
    buff += resp

# Execute whatever command and wait for a prompt again.
chan.send('ls\n')
buff = ''
while not buff.endswith('some-prompt$ '):
    resp = chan.recv(9999)
    buff += resp

# Now buff has the data I need.
print 'buff', buff

ssh.close()