php - phpseclib not working to execute commands remotely -
i stuck problem in php last 3 days. couldn't find solution yet.
i have cent os remote machine , ubuntu local machine. have php script named test.php
in local machine want run linux commands in remote machine using php script. used phpseclib connecting remote machine. following php script test.php
.
<?php include('net/ssh2.php'); define('net_ssh2_logging', net_ssh2_log_complex); $ssh = new net_ssh2('10.3.2.0'); if (!$ssh->login('makesubdomain','abcdabcd')) { exit('login failed'); } echo $ssh->exec('/usr/local/listdomain.backup/test/makedir.sh'); ?>
i can't use root
user here since root login has been disabled in remote cent os machine. created makesubdomain
user , gave sudo privileges, without password adding makesubdomain all=(all) nopasswd: all
in /etc/sudoers
file.the below 1 shell script resides in 10.3.2.0
sudo -h sh -c ' mkdir /usr/local/testdir if [ $? -eq 0 ];then echo "success"; else echo "not success"; fi '
but when run php script terminal using command php test.php
showing error sudo: sorry, must have tty run sudo
. ultimately, shall need test.php
, makedir.sh
creating directory testdir
specified in .sh file using given php script user makesubdomain
. please advice beginner in php.
(note : can run makedir.sh
file in remote machine, command sudo ./makedir
user makesubdomain
, without prompting sudo password)
edit
i had commented defaults requiretty
in /etc/sudoers
given in http://www.unix.com/shell-programming-scripting/201211-sudo-sorry-you-must-have-tty-run-sudo.html, , working fine. can have other option without doing ?
try calling $ssh->enablepty()
before doing $ssh->exec()
.
Comments
Post a Comment