user3321425
user3321425

Reputation: 201

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');
?>

Upvotes: 0

Views: 377

Answers (1)

Matt The Ninja
Matt The Ninja

Reputation: 2731

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

Upvotes: 1

Related Questions