How To Execute SSH Commands Via PHP

0 votes

I am looking to SSH out via PHP. What is the best/most secure way to go about this? I know I can do:

shell_exec("SSH user@host.com mkdir /testing");

How to do that?

Oct 30, 2020 in PHP by kartik
• 37,490 points
252 views

1 answer to this question.

0 votes

Use phpseclib, a pure PHP, SSH implementation. An example:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
answered Oct 30, 2020 by Niroj
• 82,580 points

Related Questions In PHP

0 votes
1 answer

How to execute PHP code from the command line?

Hello @kartik, the php command offers two switches to ...READ MORE

answered Oct 1, 2020 in PHP by Niroj
• 82,580 points
81 views
0 votes
1 answer

How to Execute php file from another php?

Hello @kartik, It's trying to run it as ...READ MORE

answered Nov 18, 2020 in PHP by Niroj
• 82,580 points
223 views
0 votes
1 answer

How to pass an array via $_GET in php?

Hii, You can pass an associative array to http_build_query() and ...READ MORE

answered Nov 22, 2020 in PHP by Niroj
• 82,580 points
96 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,580 points
462 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,580 points
5,657 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,580 points
656 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,580 points
499 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,580 points
6,231 views
0 votes
1 answer

How to Execute PHP function with onclick?

Hello @kartik, In javascript, make an ajax function, function ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,580 points
8,485 views
0 votes
1 answer

How to delete a file via PHP?

Hello @kartik, The following should help realpath — Returns canonicalized ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,580 points
61 views