【问题标题】:ssh cannot connect to git server in phpssh 无法在 php 中连接到 git 服务器
【发布时间】:2019-02-06 01:20:39
【问题描述】:

我可以通过终端连接远程 git 服务器并与之交互,但无法使用 PHP。我正在尝试执行以下命令:

GIT_SSH_COMMAND="ssh -vvv -i ~/.ssh/id_rsa -F /dev/null" \
/usr/local/bin/git push -u origin master

如果我在终端中执行相同的命令,它就没有问题。我在互联网上搜索了答案,但找不到有效的解决方案。

现在请记住,repo 还不存在。我正在尝试通过此命令创建它。我确实在几分钟前使用这个确切的命令成功地创建了另一个仓库。知道我缺少什么吗?

这是调试输出。

array:49 [▼
  0 => "OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011"
  1 => "debug1: Reading configuration data /dev/null"
  2 => "debug1: Connecting to git.modernizedmedia.com [208.53.61.173] port 22."
  3 => "debug1: Connection established."
  4 => "debug1: identity file /Users/greenorange/.ssh/id_rsa type 1"
  5 => "debug1: identity file /Users/greenorange/.ssh/id_rsa-cert type -1"
  6 => "debug1: Enabling compatibility mode for protocol 2.0"
  7 => "debug1: Local version string SSH-2.0-OpenSSH_6.2"
  8 => "debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1"
  9 => "debug1: match: OpenSSH_6.6.1 pat OpenSSH*"
  10 => "debug1: SSH2_MSG_KEXINIT sent"
  11 => "debug1: SSH2_MSG_KEXINIT received"
  12 => "debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none"
  13 => "debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none"
  14 => "debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent"
  15 => "debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP"
  16 => "debug1: SSH2_MSG_KEX_DH_GEX_INIT sent"
  17 => "debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY"
  18 => "debug1: Server host key: RSA ae:63:f0:7f:aa:62:5d:ac:ef:98:d6:66:a9:9c:4d:ce"
  19 => "debug1: Host 'git.modernizedmedia.com' is known and matches the RSA host key."
  20 => "debug1: Found key in /Users/greenorange/.ssh/known_hosts:64"
  21 => "debug1: ssh_rsa_verify: signature correct"
  22 => "debug1: SSH2_MSG_NEWKEYS sent"
  23 => "debug1: expecting SSH2_MSG_NEWKEYS"
  24 => "debug1: SSH2_MSG_NEWKEYS received"
  25 => "debug1: SSH2_MSG_SERVICE_REQUEST sent"
  26 => "debug1: SSH2_MSG_SERVICE_ACCEPT received"
  27 => "debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password"
  28 => "debug1: Next authentication method: publickey"
  29 => "debug1: Offering RSA public key: /Users/greenorange/.ssh/id_rsa"
  30 => "debug1: Server accepts key: pkalg ssh-rsa blen 535"
  31 => "debug1: key_parse_private_pem: PEM_read_PrivateKey failed"
  32 => "debug1: read PEM private key done: type <unknown>"
  33 => "debug1: read_passphrase: can't open /dev/tty: Device not configured"
  34 => "debug1: Next authentication method: password"
  35 => "debug1: read_passphrase: can't open /dev/tty: Device not configured"
  36 => "debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password"
  37 => "Permission denied, please try again."
  38 => "debug1: read_passphrase: can't open /dev/tty: Device not configured"
  39 => "debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password"
  40 => "Permission denied, please try again."
  41 => "debug1: read_passphrase: can't open /dev/tty: Device not configured"
  42 => "debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password"
  43 => "debug1: No more authentication methods to try."
  44 => "Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)."
  45 => "fatal: Could not read from remote repository."
  46 => ""
  47 => "Please make sure you have the correct access rights"
  48 => "and the repository exists."
]

【问题讨论】:

  • read_passphrase: can't open /dev/tty: Device not configured" /Users/greenorange/.ssh/id_rsa 是您希望加载的私钥吗?
  • 是的,这是正确的私钥。我该如何解决这个错误?为什么在终端中运行命令时看不到它?
  • 您可能正在运行 ssh-agent。见help.github.com/articles/working-with-ssh-key-passphrases。机器帐户私钥的一种解决方案是没有密码
  • 好的,有道理。关于如何解决问题的任何建议?我是否只需要使用没有附加密码的新 RSA 密钥?
  • 这绝对是一种解决方案

标签: php git ssh


【解决方案1】:

这里发现问题

read_passphrase:无法打开 /dev/tty:设备未配置

您的私钥需要一个无法输入的密码,因为没有终端。由于您的 ssh-agent,您在终端中运行命令时可能看不到此内容。

https://help.github.com/articles/working-with-ssh-key-passphrases/

一种解决方案是为远程服务创建一个没有密码的新密钥对。

这样做的安全隐患是,任何拥有新公钥的远程服务现在都只与私钥副本(即您的本地计算机帐户)一样安全。随心所欲地评估风险。

【讨论】:

    猜你喜欢
    • 2016-09-02
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 2020-11-02
    相关资源
    最近更新 更多