• Campus Karma

Login

Adding user to Linux using PHP

PHP Code:

<?php
//including phpseclib for ssh connect
include('Net/SSH2.php');

//Username and Password
$username = $_POST['user'];
$password = $_POST['pass'];

//Creating a salt value for encryption
$salt = "12345678"; //Any random 8 char of your choice

//connecting to linux using ssh
$ssh = new Net_SSH2('myservername.com:22');
$ssh->login('myuserid', 'mypassword') or die("Login failed");
$ssh->getServerPublicHostKey();
$cmd = "sudo useradd -m -p $(mkpasswd -m sha-512 $password $salt) $username";
$cmdr = $ssh->exec($cmd);
?>

That's it.!

Enjoy.

If you have any queries, feel free to drop ur message in the comment box.