Stackoverflow的新功能,所以首先,你好。ssh使用python没有RSA密钥
我正在为我的学校开发一个小项目,该项目应该是开源Unison程序的一个自定义gui(用python作为教育挑战,因为我从来没有用过python)。我们正试图让学生和员工通过尽可能少的输入来启动此程序(如果您愿意,可以在白板上打字),从而在家中和学校同步文件夹。界面应该只是他们的学校用户名和密码,gui包装应该只是将用户名和密码发送到Unison并同步它们。
问题是Unison反过来启动SSh并提示输入密码,但是python subprocess.communicate(input)方法不会让ssh获取密码。我意识到ssh只会接受来自终端的输入,我无法弄清楚如何欺骗它。我读过一些关于使用伪终端的东西,但我仍然难倒了。 RSA密钥将是理想的解决方案,但生成它们然后将它们放置在远程服务器上仍然需要我至少使用一次密码登录,这需要上述解决方案,或者终端不是白痴证明。如果我在贴吧。而且任何一般蟒蛇提示也将是如果你愿意赞赏
def startSync(self):
'''
'''
userName = self.userNameIn.get()
userPass = self.userPassIn.get()
localDir = "/Users/localuser/syncFolder/"
remoteDir = " ssh://schoolServer/remotesyncFolder" #for testing purposes, I set this to my own home machine which logs into my own account if I don't provide [email protected]
unisonExecRemotePath = " -servercmd /Users/RemoteMe/unison" #unison is the unix executable responsible for launching unison on the remote system
silenceCmdPrompts = " -silent" #keeps unison from displaying directory differences and asking if its okay to sync
executionString = "./unison" + localDir + remoteDir + unisonExecRemotePath + silenceCmdPrompts
mainProcess = subprocess.Popen(executionString,shell = True, stdin = subprocess.PIPE)
mainProcess.communicate(userPass)
执行字符串工作在那里终端的罚款。
谢谢!
齐奏用户手册:http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html
编辑:我还要指出的是,虽然我目前OSX和Linux下的发展,我最终将不得不作出这个Windows兼容的,因为我的大部分学校的学生运行Windows作为他们的主要(或唯一)机器。
我只是试图测试这个ouside我的项目,正是你在那里(显然与实际主机虽然),没有任何反应。稍微停顿一下,然后回到没有消息的bash提示符。 我尝试从我的上面的代码中添加整个执行行,也许它只是关闭,如果没有给它,但它做同样的事情。 – Hiroshi
确保您传递给child.expect()的参数与服务器为您提供的密码提示匹配。另外,您可能需要在child.sendline(mypassword)之后调用child.interact()。自从我使用pexpect以来,这已经有一段时间了,但它是工作的工具。 –
工作!谢谢! :) – Hiroshi