After upgrading the VPS, due to the compatibility problem of Ubuntu upstart and OpenVZ, the SSHD service does not start automatically, after attempting veportal console and File Manager and submitting technical support can not solve the problem.
Can only rely on their own, the general idea is to perform the SU in PHP to execute the sshd service, because WordPress is still alive, and can be directly in the background edit the subject-related PHP script. Just insert the prepared code snippet into the header.php and visit the homepage in the browser.
Related Code logic
1. Use PHP's proc_open to open a process, redirect stdin, stdout, stderr, where a python program is executed.
2. Open a pty in this Python program and run an SH.
3. Using stdin pipe in step 1 to send the SU command to a python program, Python writes the command data from stdin to the PTMX, while the stdin, stdout, and stderr of SH are redirected to and PYT Hon Open ptmx paired with Pts. In other words, the SU command will eventually be transferred to the SH process.
4. The SH process naturally executes the SU command, at which point the stdin of the SU process, stdout, and stderr will also be redirected to that pts.
5. After a period of sleep (mainly such as Su really ran up), and then write the password, the data flow process and steps 3, 4 consistent.
Related Code Snippets:
Copy Code code as follows:
<?php
$descriptorspec = Array (
0 => Array ("Pipe", "R"),/stdin
1 => Array ("Pipe", "w"),//stdout
2 => Array ("Pipe", "w")//stderr
);
$process = Proc_open ("Python-c ' Import pty; Pty.spawn (\ "/bin/sh\") ' ", $descriptorspec, $pipes);
if (Is_resource ($process)) {
Fwrite ($pipes [0], "su-c ' service ssh start ' root\n");
Fflush ($pipes [0]);
Sleep (3);
Fwrite ($pipes [0], "password\n");
Fflush ($pipes [0]);
Fclose ($pipes [0]);
Fclose ($pipes [1]);
Fclose ($pipes [2]);
Proc_close ($process);
}
?>