windows server 2016 использует git ssh(ошибка проверки ключа хоста)

#git #ssh

Вопрос:

Я могу сделать это в CMD под пользователем temp_npp.Однако при выполнении в PHP exec он возвращает ошибку. Пользователь, которого я печатаю при удаленном доступе к PHP, отличается от пользователя, которого я печатаю при выполнении моего CMD.Но я также поместил соответствующие файлы.ssh в каталог конфигурации пользователя удаленного выполнения.

Вот код

 $pro_dir = __DIR__;
$pro_dir  = iconv('utf-8', 'gb2312', $pro_dir);
echo $pro_dir;
echo "<br/>";
chdir($pro_dir);
echo "<br/>";
echo getcwd();
echo "<br/>";
echo shell_exec('echo %username% 2>amp;1');
echo "<br/>";
echo shell_exec('echo %userprofile% 2>amp;1');
echo shell_exec('echo %HOMEDRIVE% 2>amp;1');
echo shell_exec('echo %SYSTEMDRIVE% 2>amp;1');

$ssh = ""F:Program FilesOpenSSHbinssh.exe"  -vvv git@gitee.com 2>amp;1";
exec($ssh,$out2);
echo "<br/>";
print_r($out2);
$shell = ""F:Program FilesGitbingit.exe" pull 2>amp;1";
exec($shell,$out);
echo "<br/>";
print_r($out);
 

Вот результаты

 WechatDatabase$ 
<br/>C:Windowssystem32configsystemprofile 
%HOMEDRIVE% 
C: 
<br/>Array
(
    [0] => OpenSSH_8.4p1, OpenSSL 1.1.1f  31 Mar 2020
    [1] => Pseudo-terminal will not be allocated because stdin is not a terminal.
    [2] => debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/.ssh/known_hosts'
    [3] => debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/.ssh/known_hosts2'
    [4] => debug2: resolving "gitee.com" port 22
    [5] => debug2: ssh_connect_direct
    [6] => debug1: Connecting to gitee.com [180.97.125.228] port 22.
    [7] => debug1: Connection established.
    [8] => debug1: identity file /.ssh/id_rsa type 0
    [9] => debug1: identity file /.ssh/id_rsa-cert type -1
    [10] => debug1: identity file /.ssh/id_dsa type -1
    [11] => debug1: identity file /.ssh/id_dsa-cert type -1
    [12] => debug1: identity file /.ssh/id_ecdsa type -1
    [13] => debug1: identity file /.ssh/id_ecdsa-cert type -1
    [14] => debug1: identity file /.ssh/id_ecdsa_sk type -1
    [15] => debug1: identity file /.ssh/id_ecdsa_sk-cert type -1
    [16] => debug1: identity file /.ssh/id_ed25519 type -1
    [17] => debug1: identity file /.ssh/id_ed25519-cert type -1
    [18] => debug1: identity file /.ssh/id_ed25519_sk type -1
    [19] => debug1: identity file /.ssh/id_ed25519_sk-cert type -1
    [20] => debug1: identity file /.ssh/id_xmss type -1
    [21] => debug1: identity file /.ssh/id_xmss-cert type -1
    [22] => debug1: Local version string SSH-2.0-OpenSSH_8.4
    [23] => debug1: Remote protocol version 2.0, remote software version Basalt-3.0.0
    [24] => debug1: no match: Basalt-3.0.0
    [25] => debug2: fd 3 setting O_NONBLOCK
    [26] => debug1: Authenticating to gitee.com:22 as 'git'
    [27] => debug3: send packet: type 20
    [28] => debug1: SSH2_MSG_KEXINIT sent
    [29] => debug3: receive packet: type 20
    [30] => debug1: SSH2_MSG_KEXINIT received
    [31] => debug2: local client KEXINIT proposal
    [32] => debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
    [33] => debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
    [34] => debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
    [35] => debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
    [36] => debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
    [37] => debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
    [38] => debug2: compression ctos: none,zlib@openssh.com,zlib
    [39] => debug2: compression stoc: none,zlib@openssh.com,zlib
    [40] => debug2: languages ctos:
    [41] => debug2: languages stoc:
    [42] => debug2: first_kex_follows 0
    [43] => debug2: reserved 0
    [44] => debug2: peer server KEXINIT proposal
    [45] => debug2: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1
    [46] => debug2: host key algorithms: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
    [47] => debug2: ciphers ctos: aes128-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr
    [48] => debug2: ciphers stoc: aes128-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr
    [49] => debug2: MACs ctos: hmac-sha2-256-etm@openssh.com,hmac-sha2-256,hmac-sha1,hmac-sha1-96
    [50] => debug2: MACs stoc: hmac-sha2-256-etm@openssh.com,hmac-sha2-256,hmac-sha1,hmac-sha1-96
    [51] => debug2: compression ctos: none
    [52] => debug2: compression stoc: none
    [53] => debug2: languages ctos:
    [54] => debug2: languages stoc:
    [55] => debug2: first_kex_follows 0
    [56] => debug2: reserved 0
    [57] => debug1: kex: algorithm: curve25519-sha256@libssh.org
    [58] => debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    [59] => debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    [60] => debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    [61] => debug3: send packet: type 30
    [62] => debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    [63] => debug3: receive packet: type 31
    [64] => debug1: Server host key: ecdsa-sha2-nistp256 SHA256:FQGC9Kn/eye1W8icdBgrQp KkGYoFgbVr17bmjey0Wc
    [65] => debug1: read_passphrase: can't open /dev/tty: No such device or address
    [66] => Host key verification failed.
)
<br/>Array
(
    [0] => Host key verification failed.
    [1] => fatal: Could not read from remote repository.
    [2] => 
    [3] => Please make sure you have the correct access rights
    [4] => and the repository exists.
)
 

Ответ №1:

 read_passphrase: can't open /dev/tty
 

Это предполагает наличие закрытого ключа, защищенного парольной фразой, который нельзя ввести в вашем неинтерактивном сеансе PHP.

Для тестирования попробуйте добавить в «каталог конфигурации пользователя удаленного выполнения» (его ~/.ssh папку) закрытый ключ без парольной фразы, чтобы проверить, работает ли он.