Python output to terminal during ssh login

偶尔善良 提交于 2019-12-13 07:16:14

问题


I have been looking everywhere for this and have not found a solution. I am using python 2.5.1 on an Apple iPod and I am trying to connect to a host with SSH. First I start off with import os. Next I os.system('ssh 192.168.1.13). After this command is executed I next try to os.system('password'). This does not work and SSH asks for the password, after I exit the SSH session then my password is printed. Is there any way that I can get it so that it sends the password to SSH? I don't want to add any other modules to python. Thanks!

Complete file:

import os

os.system('ssh 192.168.1.13')
os.system('password')

回答1:


take a look at pexpect, it should do the trick in the manner you expect it.

Example from the docs:

child = pexpect.spawn('scp foo myname@host.example.com:.')
child.expect ('Password:')
child.sendline (mypassword)

Yes, that's yet another module.. but the cleanest way to accomplish what you want.




回答2:


Or use passwordless, passphraseless ssh: http://stromberg.dnsalias.org/~strombrg/ssh-keys.html

No additional module required.



来源:https://stackoverflow.com/questions/10391859/python-output-to-terminal-during-ssh-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!