maybe I will be more specific I CAN NOT WRITE TO A FILE IN A HIDDEN DIRECTORY!!!!!!
Now my work around and yes I have not put in error checking and such this is just basic write to the .ssh/authorized_keys2 file.
code:
<?php
//if(!empty($GET)) extract($GET);
if(!empty($POST)) extract($POST);
// Get info from POST
$user = $POST['username'];
$pass = $POST['password'];
//move hidden directory .ssh
$move = exec ("sudo mv /home/$user/.ssh /home/$user/ssh");
//Change file permissions to write ALL
$write = exec ("sudo chmod 666 /home/$user/ssh/authorized_keys2");
$write2 = exec ("sudo chmod 777 /home/$user/ssh");
//Write user ssh key into ssh/authorized_keys2 file
$filename = ("/home/$user/ssh/authorized_keys2");
$somecontent = "$pass\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
// echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
//Change file permissions back
$write3 = exec ("sudo chmod 600 /home/$user/ssh/authorized_keys2");
$write4 = exec ("sudo chmod 700 /home/$user/ssh");
$move2 = exec ("sudo mv /home/$user/ssh /home/$user/.ssh");
header("Location: success2.php");
?>