Home  >  Article  >  Backend Development  >  关于使用ssh2_exec修改user密码的有关问题

关于使用ssh2_exec修改user密码的有关问题

WBOY
WBOYOriginal
2016-06-13 13:06:14847browse

关于使用ssh2_exec修改user密码的问题
我要把用户名test的密码改一下,有经验的朋友看下哪里错了?感觉用ssh2_exec不太好,是不是得shell?是的话,应该怎么写???先谢谢了!

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$con = ssh2_connect( 'IP', '22' );
    if ( ssh2_auth_password( $con, 'root', 'root_pwd' ) ) {
            $stream = ssh2_exec( $con, "passwd test\n123456\n123456\n" ); //把用户名“test”的密码改成“123456”
            echo $stream;
    } else echo 'Cannot log in';



------解决方案--------------------
"passwd test\n123456\n123456\n" 这个应该是不行的, 

试下这样
echo "123456" | passwd "test" --stdin
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn