PHP + SSH如何解决:“错误:ssh2_connect():启动SSH连接时出错(-4):接收到无效的MAC?" [英] PHP + SSH How can I fix: "Error: ssh2_connect(): Error starting up SSH connection(-4): Invalid MAC received?"

查看:904
本文介绍了PHP + SSH如何解决:“错误:ssh2_connect():启动SSH连接时出错(-4):接收到无效的MAC?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理使用ssh2_connect构建的项目,以从服务器下载文件.该项目正在运行的生产服务器可以正常运行,但是在我的运行OSX 10.8的Mac上使ssh2_connect正常工作是有问题的.

Working on a project that was built using ssh2_connect to download files from a server. The production server the project is running on works, but getting ssh2_connect to work on my Mac running OSX 10.8 is proving to be problematic.

以下命令:

ssh2_connect("myhost", 22);

产生以下错误:

Error: ssh2_connect(): Error starting up SSH connection(-4): Invalid MAC received

我可以从命令行连接,所以我知道这不是系统范围的SSH问题.有谁知道如何调试或解决此问题?在此先感谢您,并希望您的孩子拥有丰富的大脑和社交技能:)

I can connect from the command line, so I know it isn't a system wide SSH issue. Does anyone know how to debug or solve this problem? Thanks in advance and may your children be blessed with large brains and social skills :)

更新:解决方案发布在下面

UPDATE: Solution posted below

推荐答案

PHP文档提供了一个提供第3个参数的示例.这篇文章的作者 http://phing.tigris.org/ds/viewMessage.do?dsForumId=1083&viewType=browseAll&dsMessageId=3022056#messagefocus (Derek Gallo)遇到了完全相同的问题,他能够为我指出正确的方向.谢谢德里克.似乎某些发行版需要额外的参数.最后,我将代码转换为使用phpseclib,因为它是一个纯PHP解决方案,不需要任何特殊模块.

The PHP documentation has an example that provides the 3rd argument. The author of this post http://phing.tigris.org/ds/viewMessage.do?dsForumId=1083&viewType=browseAll&dsMessageId=3022056#messagefocus (Derek Gallo) had the exact same issue, and he was able to point me in the right direction. Thanks Derek. It seems that some distributions require the extra parameters. In the end, I converted my code to use phpseclib as it is a pure PHP solution that doesn't require any special modules.

$methods = array(
  'kex' => 'diffie-hellman-group1-sha1',
  'client_to_server' => array(
    'crypt' => '3des-cbc',
    'comp' => 'none'),
  'server_to_client' => array(
    'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
    'comp' => 'none'));

ssh2_connect("myhost", 22, $methods);

这篇关于PHP + SSH如何解决:“错误:ssh2_connect():启动SSH连接时出错(-4):接收到无效的MAC?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆