Skip to content

Instantly share code, notes, and snippets.

@esolitos
Created November 3, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esolitos/988031f172c517dfc628cac29c6bc14a to your computer and use it in GitHub Desktop.
Save esolitos/988031f172c517dfc628cac29c6bc14a to your computer and use it in GitHub Desktop.
<?php
$sshd_conf = file_get_contents('/etc/ssh/sshd_config')
?>
<h2>Before</h2>
<pre>
<?php var_dump($sshd_conf) ?>
</pre><?php
$SnD = array(
'@#(PermitEmptyPasswords)(.+)@' => '$1 yes',
'@#(PermitRootLogin)(.+)@' => '$1 yes',
'@#(PasswordAuthentication)(.+)@' => '$1 yes',
);
$fixed_conf = preg_replace(array_keys($SnD), array_values($SnD), $sshd_conf);
?>
<h2>After</h2>
<pre>
<?php var_dump($fixed_conf) ?>
</pre><?php
$result = file_put_contents('/etc/ssh/sshd_config', $fixed_conf);
exec('kill -HUP ')
?>
<h2> Replaced? </h2>
<pre><?php var_dump($result); ?> </pre>
<?php
shell_exec('nohup sudo /usr/local/bin/sshd-generate-keys.sh > keygen-out.log 2>&1');
shell_exec('nohup sudo /usr/sbin/sshd -f /etc/ssh/sshd_config > ssh-out.log 2>&1');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment