A
A
Alexey Kos2015-03-26 21:45:34
linux
Alexey Kos, 2015-03-26 21:45:34

How to change root password on Linux using ssh2?

Hello. How to change root password on Linux using ssh2? I searched on Google, but alas, I did not find anything.
My code:

$connection = ssh2_connect('0.0.0.0', 22);
ssh2_auth_password($connection, 'root', 'pass');

$stream = ssh2_exec($connection, 'passwd 123321 \n 123321 \n');
    stream_set_blocking($stream, true);
    $data = '';
    while($buffer = fread($stream, 4096)) {
        $data .= $buffer;
    }
    echo $data."<hr/>";
  fclose($stream);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2015-03-26
@djalexsey

echo -e "new_password\nnew_password" | (passwd --stdin $USER)

S
ShamblerR, 2015-03-27
@ShamblerR

Damn, what are you doing there at all?
Firstly, php must have access to the root account, which is not really feng shui.
well, let's say your apache is added to group 0. ok now, when the system is hacked, it's not the site that gets into a vulnerability, but the whole system as a whole. well, let
's change the passwd password in the console. What for to write a bunch of code?
Ladnov so impatient but you do not know how to use? exec

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question