Giter Club home page Giter Club logo

pecl-networking-ssh2's People

Contributors

andypost avatar bjori avatar blar avatar cmb69 avatar derickr avatar edinkad avatar fmk avatar jan-e avatar jentian avatar johannes avatar kallez avatar kaplanlior avatar langemeijer avatar liborm85 avatar mageekguy avatar majkl578 avatar mhagstrand avatar mindnever avatar mrngm avatar nattynarwhal avatar petk avatar pierrejoye avatar qjavax avatar remicollet avatar rlerdorf avatar rposky avatar sean-der avatar sgolemon avatar weltling avatar wez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pecl-networking-ssh2's Issues

ssh2_auth_password Password parameter does not work as expected

I'm using https://pecl.php.net/package/ssh2 module in PHP. The password parameter is not working as intended.

This Works:

but if I put that code into a function and pass the password into the function ssh2_connect() authentication will fail. Password will only work if I manually supply it in the code. My use case is pulling the password from a database and passing it into a custom function parameter and then pass it to ssh2_connect().

I had the issue on windows PHP 7.4 using the 1.2 SSH2 module
I then upgraded to version PHP 8.1 and now using 1.3 SSH2 module on windows.
I get the same behavior on both versions.

ssh2_auth_pubkey_file caused "segmentation fault" when enable xdebug

#...

dump(php_uname('a'));
dump(phpversion('ssh2'));
dump(phpversion('xdebug'));

dump(php_uname('a'));
dump(phpversion());
dump(phpversion('ssh2'));
dump(phpversion('xdebug'));

$ssh_conn = ssh2_connect($my_hostname, 22222, ['hostkey' => 'ssh-rsa']);
dump($ssh_conn);
$auth_result =  ssh2_auth_pubkey_file($ssh_conn, $my_username,
    '~/.ssh/id_rsa.pub',
    '~/.ssh/id_rsa');
dump($auth_result);

"Darwin myhostname.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64"
"8.1.6"
"1.3.1"
false
SSH2 Session resource @556
true

"Darwin myhostname.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64"
"8.1.6"
"1.3.1"
"3.1.4"
SSH2 Session resource @556
[1]    17604 segmentation fault  myscript.php
------

Compatibility with PHP 8.1 windows dll

Under PHP 8.0.13 all ok
Under PHP 8.1.0 I recived:
Warning: PHP Startup: ssh2: Unable to initialize module
Module compiled with module API=20200930
PHP compiled with module API=20210902

Modern SSH hostkey methods compatibility

According to documentation, ssh2_connect currently supports only ssh-rsa and ssh-dss hostkey methods, but both of them are deprecated:

  • ssh-dss disabled since OpenSSH 7.0 (2015)
  • ssh-rsa disabled since OpenSSH 8.8 (2021)

So, its unable to connect to server, which uses modern OpenSSH versions.

Library should be updated to support more modern hostkey methods.

SSH2 fails after upgrading to PHP8.2 and Debian Bookworm - ssh2_auth_pubkey_file(): Authentication failed

After upgrading to Debian Bookworm and PHP 8.2 it's no longer possible to connect to remote server via PHP and SSH2

The public/private key works because it's possible to connect via command line

ssh remote-server.com

code

$user 			= 'root';
$host 			= 'remote-server.com';
$private_key 	= '/root/.ssh/id_rsa';
$public_key 	= '/root/.ssh/id_rsa.pub';

if(!is_readable($private_key) || !is_readable($public_key)){
	echo "RSA keys not found\n";
}

echo 'private key: '.file_get_contents($private_key)."\n";
echo 'public key: '.file_get_contents($public_key)."\n";
echo "host: $host\n";
echo "user: $user\n";

if(!$session = ssh2_connect($host)){
	echo "Could not connect to '$host'\n";
}

if(!ssh2_auth_pubkey_file($session, $user, $public_key, $private_key)){
	echo "Could not authenticate to '$host'\n";
}

output

# php test_ssh.php
private key: -----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
...
hoyaUZrhPmUPAAAAHHJvb3RAQVBJc2Nhbi1JbnRlbC1YZW9uLTY0Z2IBAgMEBQY=
-----END OPENSSH PRIVATE KEY-----

public key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC0geHl2dKCkd9UkU/2WtVBqo4NEhnprMzAV6hVhm7TAvK63GQN1xlAGlgagb7S5u1vET3BOAu+c8qPOkrvofhCKNF5a7v3uEh/u/oysd0Ckj6IA8spRdCXe3JbmXCHp85VadYjylwILC0drKetdMhXnHNnFHdvJDRIbVCqrO1j17kAJ9kf3cW/lsmqng9rPPGB8gozxcW6N5f3hNiSwDOo9ex0su37xflwxY2Hi4QYk1tdp7GO9YlaXlNS+s4Q47aU3dGsn5nMWlxUdT3yD2DJDdp7Bz24wLY3QFpKMbRqHC66YWIbe29Rr53ESUGukrNedZobanuW0f5wQ2xvFTB9BOXt0Bhf8OXVyNr1K79UEqaCSnpU3rGRA71lOxeRdZUN9EyHaji0rlq8kOCGBKgMwQ96fo2T1x8xikcWEiPVC+Bhd4pyOwq2G9Ihi3lAqV45zqm/5gx3Te7OtAAJIjb3aI7um+di6SL0DabHkkQH4ZzeeeikhV+ZmVUt8/guldpkZrPy7COqG043X27kk/meP/8mAnAS9mv7ircBvlW0IUHL7wwndJc0aGDwmrKaXk64qCS+80k+42BPuZAMk8dSrFJsu8vcYwuTVxn281T55t8N/JgGEkmNxEsP4VFM0DxQfgsktiPiBEPxe3S8P/ipPhx2Mn1JrohbIDahPDTyfQ== root@APIscan-Intel-Xeon-64gb

host: remote-server.com
user: root
PHP Warning:  ssh2_auth_pubkey_file(): Authentication failed for root using public key: Username/PublicKey combination invalid in /root/test_ssh.php on line 21

Warning: ssh2_auth_pubkey_file(): Authentication failed for root using public key: Username/PublicKey combination invalid in /root/test_ssh.php on line 21
Could not authenticate to 'worker.dynaccount.com'

PHP

# php -v
PHP 8.2.15 (cli) (built: Jan 20 2024 14:14:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies

SSH client

# ssh -V
OpenSSH_9.2p1 Debian-2+deb12u2, OpenSSL 3.0.11 19 Sep 2023

SSH remote server

# ssh -V
OpenSSH_9.2p1 Debian-2+deb12u2, OpenSSL 3.0.11 19 Sep 2023

Generating public/private keys (the keys are created without passphrase)

ssh-keygen -t rsa -b 4096

ssh2_scp_send() truncates files, incomplete file saved on remote server

Description

The following code:

<?php
$ssh2 = ssh2_connect('example.com');
ssh2_auth_pubkey_file($ssh2, 'ubuntu', 'pubkey', 'privkey');
$sftp = ssh2_sftp($ssh2);
ssh2_sftp_unlink($sftp, 'myfile');
ssh2_scp_send($ssh2, 'myfile', 'myfile');
$myfile = ssh2_sftp_stat($sftp, 'myfile');
if ($myfile['size'] != filesize('myfile')) echo 'File size mismatch, local: ' . filesize('myfile') . ', remote: ' . $myfile['size'] . "\n";

Resulted in this output:

File size mismatch, local: 3938770, remote: 2310144

But I expected this output instead:

I should get no output as the file sizes on the local and remote servers should match. ssh2_scp_send() is not sending the whole file to the remote server.

PHP Version

PHP 8.1.2

Operating System

No response

Cannot specify timeout

I'm using ssh2 extension. Unfortunately sometimes ssh2_sftp function waits forever because there is no way to specify timeout.

Please consider adding parameter timeout to ssh2_connect function (as in ftp_connect) or implement method ssh2_settimeout. I think it can be easily implemented because libssh supports libssh2_session_set_timeout().

PHP 7.4 Comatibility

% pecl install ssh2
pecl/ssh2 requires PHP (version >= 4.0.0, version <= 6.0.0), installed version is 7.4.20
No valid packages found
install failed

ssh2_exec: retrieve the command exit code

What about adding a new function to retrieve the exit code if a command executed with ssh2_exec()?

I'm thinking about a new ssh2_get_exit_status() function that could be used like this:

$connection = ssh2_connect($host);
ssh2_auth_password($connection, $username, $password);
$channel = ssh2_exec($connection, $command);
$exitCode = ssh2_get_exit_status($channel);
fclose($channel);

And internally, ssh2_exec() could use libssh2_channel_get_exit_status().

ssh2_exec execution stops after 32kb of data

ssh2_exec works fine with short commands but fails with PHP Warning: ssh2_exec(): Unable to request command execution on remote host when trying to send long commands (41269 chars in my example). The magical limit seems to be 32KB.

Tested with v1.2 on Debian 11 with PHP 7.4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.