PHP脚本中的SSH [关闭]

preface I am setting up a web environment intended to be hosted on a local server strictly accessible on the local network. There's about 50 employees within the office and no employee has an assigned computer.

problem Via an HTML form with parameters ('host', 'username', 'password'), the PHP will attempt an ssh.

Main Point Basically I'm trying to find out how to interact with ssh from PHP (i.e. edit and view files/directories.

ie user enters username, password into an html form. My php code takes this information and (if valid) ssh into their user on server. Giving them access to directories and files.

You can use phpseclib to handle the SSH. Here is some simple code to get you started:

<div>
<?php

    set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
    include('Net/SSH2.php');

    function display_home_directory($hostname, $username, $password) {
        $ssh = new Net_SSH2($hostname);
        if (!$ssh->login($username, $password)) {
            echo 'Login Failed';
        }
        echo '<pre>';
        echo $ssh->exec('pwd');
        echo $ssh->exec('ls -la');
        echo '</pre>';
    }

    display_home_directory('example.com', 'myusername', 'mypassword');
?>
</div>