【问题标题】:scp host key verification failed when executed by phpphp执行时scp主机密钥验证失败
【发布时间】:2013-02-04 12:17:37
【问题描述】:

我正在尝试使用 scp 来复制文件。我使用 PHP 的命令 shell_exec 来执行这个命令:

scp -i/home/raul/nueva_clave -q -v /home/raul/www/CA/app/tmp/ImagenWeb TA-adm@127.0.0.1:/home/TA-adm/images/IMG_3846.JPG 2>&1

服务器地址是 127.0.0.1 因为我还在开发脚本。稍后我会更改它。

我使用 scp 而不是 PHP 的 ssh2_scp_send 因为我不想在我的项目中写入服务器的密码。相反,我想使用公钥。但是当我在 PHP 中执行时,结果如下:

Executing: program /usr/bin/ssh host 127.0.0.1, user TA-adm, command scp -v -t -- /home/TA-adm/images/IMG_3846.JPG
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 22.
debug1: Connection established.
debug1: SELinux support disabled
Could not create directory '/nonexistent/.ssh'.
debug1: identity file /home/raul/nueva_clave type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/raul/nueva_clave-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 2d:71:67:30:89:c0:1a:64:41:b5:07:8f:6d:c5:9f:13
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
lost connection

如果我在终端中与我的用户一起执行此命令,我没有问题。我想问题是用户nobody正在执行scp。我正在使用 Ubuntu。

【问题讨论】:

  • 密钥文件是加密的,因为你是通过scp运行的,所以没有终端可以显示密钥的解密密码提示
  • 我已经在我的服务器中生成并安装了一个公钥,因此 scp 不会提示输入任何密码。
  • 那么也许钥匙串被加密了,这就是提示的内容。无论哪种方式,错误文本中的read_passphrase 行基本上都说明了一切。有些东西正在提示输入密码,但不能,因为没有控制终端来显示提示。

标签: php linux scp


【解决方案1】:

(由 OP 在问题编辑中回答。移至此处。见Question with no answers, but issue solved in the comments (or extended in chat)

OP 写道:

解决了。我使用了以下选项:

-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

所以scp 命令不会尝试将主机插入到用户nobody 的文件known_host 文件中(scp 无法创建文件,因为用户nobody 也没有家~/.ssh) .

【讨论】:

    猜你喜欢
    • 2017-09-10
    • 1970-01-01
    • 2016-02-02
    • 2021-12-25
    • 2013-02-16
    • 1970-01-01
    • 2020-07-15
    • 2018-10-04
    • 2022-12-20
    相关资源
    最近更新 更多