Use local file containing password on ssh2_exec() - Help

Hello:

I would like to ask for your expertise and help me understand how I can perform the following task.

I am using the following code to execute commands on remote machines,… So far, I have been able to execute the sudo commands I require by using a simple text file located in the remote machine itself which contains the password in it, but I am in need to NOT have this stored remotely and use a server located text file to pass the information through.

here is what I am using and working with the file in the remote machine:

<?php $connection =@ssh2_connect('testunit' , 22); echo 'Conection to Remote Unit is starting...
'; if(!($connection)){ echo 'Unable to to execute connection to remote unit!
'; exit(1); } echo 'Remote Unit Found!... Authenticating...
'; if (!@ssh2_auth_password($connection, 'admin' , 'password')){ echo 'Failed to Authenticate to Remote Unit!'; exit(1); } echo 'Authentication Successful!...
'; $stdout_stream = ssh2_exec($connection, 'sudo -u admin -S shutdown -r now < secret.file'); [sub]<--- ( here is where I want to find a way to redirect to a different text file located at the server).[/sub] sleep(1); $stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR); while($output = fgets($stderr_stream)) {flush(); echo $output;} echo '

'; while($output = fgets($stdout_stream)) { flush(); echo '
'.$output.'
';} fclose($stdout_stream); ?>

I would like to add that I am aware of the security issues this may imply, and that all these units are inside a secured network without internet access… Yet… If there is a way to pass sudo commands in other ways, I am certainly open to hear about them!..

Thanks!

HT

Thanks everyone…

I found a different way to get this process done using a very different approach.

Regards…

htakeuchi

Sponsor our Newsletter | Privacy Policy | Terms of Service