简体   繁体   中英

ssh2_exec password encryption

How can I call ssh2_exec function in php to execute a command in a remote server without hardcoding my server password?

Here's the PHP manual reference:

<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'myusername', 'mypasswordisvisibleforeveryone');

$stream = ssh2_exec($connection, '/usr/local/bin/php -i');
?>

I would setup a user just for access from this server then user a public ssh key

You can connect like that using the following code...

ssh2_auth_pubkey_file($ssh, 'user', '/location/to/.ssh/id_rsa.pub', '/location/to/.ssh/id_rsa', 'passphrase');

where $ssh is your $connection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM