After upgrading the VPS, due to the compatibility of Ubuntu upstart and OpenVZ, the SSHD service does not start automatically, after trying the veportal console and File Manager and submit technical support can not solve the problem.
Only on their own, the general idea is to do the SU command in PHP to perform the sshd service, because WordPress is still alive, and can be directly in the background to edit the topic related PHP script. Just insert the prepared code snippet into header.php and visit the homepage in your browser.
Related Code logic
1. Using PHP proc_open to open a process, redirect stdin, stdout, stderr, here will execute a python program.
2. Open a pty in this Python program and run an SH.
3. Using the redirected stdin pipe in step 1 to send the SU command to the Python program, Python writes the command data from stdin to PTMX, when the stdin, stdout, and stderr of SH are redirected to the PYT Hon Open ptmx on paired pts. This means that the SU command will eventually be transferred to the SH process.
4. The SH process naturally executes the SU command, when the SU process's stdin, stdout, stderr will also be redirected to that pts.
5. After sleep for some time (mainly when Su really ran up), and then write the password, the data flow process is consistent with steps 3 and 4.
Related Code snippet:
Copy the Code code as follows:
$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);
}
?>
http://www.bkjia.com/PHPjc/788643.html www.bkjia.com true http://www.bkjia.com/PHPjc/788643.html techarticle after upgrading the VPS, due to Ubuntu upstart and OpenVZ compatibility issues, resulting sshd service does not automatically start, in the attempt to veportal console with File Manager and submit technical support ...