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.

  • Do you have the right to run a command on the router? - Naumov
  • Yes. For tests I use my account. - Surf
  • so try to run the command on the router just as you try in php - Naumov
  • so I do, on the router: show port - returns a list of all ports. - Surf
  • Without sudo? Etc. etc. - Naumov

0