Hello.
There is a need for ssh to collect information from different network hardware: alu, cisco, jun, linux-server. At the same time automate the process using php.
The first attempts were successful. On linux-hosts comes without problems, executes exec-commands, returns the result.
But as soon as it came to the routers, I was a fiasco.
Ultimately, I have the following code:
function ssh_connect($host, $port, $login, $password, $cmd){ $connection = ssh2_connect($host, $port); if (!(ssh2_auth_password($connection, $login, $password))) { echo "ΠΡΠΈΠ±ΠΊΠ° Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ \r\n" ; }else{ if(!($stream = ssh2_exec($connection, $cmd))){ echo "ΠΠ΅ ΡΠ΄Π°Π»ΠΎΡΡ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ \r\n" ; }else{ stream_set_blocking($stream, true); $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO); echo stream_get_contents($stream_out); } } } $cmd = "show port" ; ssh_connect("10.70.70.10", "22", "login", "password", $cmd);
Returns:
PHP Warning: ssh2_exec (): Unable to request command execution on / 11/www/ssh.ms/ssh.php on line
Command failed
In this case, the command is valid.
Perhaps the ssh client needs to somehow accept the RSA2-key that the ssh server offers on the router? At least I see this by going to the router using Putty. How to do this in PHP - not yet understood.
Colleagues, if you have thoughts on how to implement this functionality, please :) I will be grateful to any ideas and leading questions.