unixtimestamp 通过PHP修改Linux或Unix口令的方法分享

WBOY
Freigeben: 2016-07-29 08:47:46
Original
1050 Leute haben es durchsucht

需要的工具和安装:
  你必须安装下面的工具和软件:
  –修改口令的Shell脚本;
  – Sudo访问权;
  – Apache or Lighttpd web服务器;
  – PHP服务端程序。
  步骤1:安装可以修改用户口令的shell脚本
  该脚本可以实际用于修改Linux用户的口令(已在Linux和FreeBSD测试)。
  例子: shell脚本代码
  #!/bin/sh # \ exec expect -f “$0″ ${1+”$@”} set password [lindex $argv 1] spawn passwd [lindex $argv 0] sleep 1 expect “assword:” send “$password\r” expect “assword:” send “$password\r” expect eof运行shell脚本(下载链接):
  $ chpasswd username password下载该脚本,然后拷贝到你的web根目录或者web服务器的其它位置(用户可读):
  $ cp chpasswd /var/www/或者,如果你使用Lighttpd web服务器:
  $ cp chpasswd /home/lighttpd步骤2:通过sudo以root身份执行命令
  Apache或Lighttpd web服务器进入后台运行后会马上使用非root权限。这样可以很好的防止口令修改,就像passwd命令需要root权限才能修改其它用户帐号的口令。
  通常, Apache 2使用www-data用户, Lighttpd使用lighttpd用户(皆为普通用户,非root用户)。使用root用户登陆,然后执行下面的命令:
  # visudo现在你的web服务器允许执行口令修改脚本(chpasswd)。如果你使用Apache web服务器,执行下面的命令:
  www-data ALL=NOPASSWD: /var/www/chpasswd或者,如果你使用Lighttpd web服务器,执行下面的命令:
  httpd ALL=NOPASSWD: /home/lighttpd/chpasswd保存和退出文件。
  步骤3.创建一个基于PHP的接口
  现在你需要写一个php脚本。这里有一个php脚本实例。你可以根据你的需要来修改。至少你需要正确设置好的shell脚本位置。打开php脚本和找到shellscript一行:
  $shellscript = “sudo /home/lighttpd/chpasswd”;修改shellscript指向到正确的位置。PHP的源代码从这里下载:
  步骤4:运行脚本
  在你的web浏览器地址栏输入网地址,你将会看到用户名和口令提示:
  如果口令修改成功,你会得到的确认提示:
  由于一些原因,如果口令修改失败,你可以参考下面提示获得更多详细的错误信息:
  步骤5:安全
  ◆永远不要通过http协议直接运行上面的脚本.而是使用https协议。
  ◆把脚本放入到受口令保护的目录。
  ◆永远不要信任用户的输入。上面的php脚本只是一个例子。在现实的生产环境中,你需要考虑采用更强大的用户输入确认。讨论PHP编程的安全超出了本文的范围。你可以参考一本好的PHP书籍或者使用你喜欢的搜索引擎搜索相关的网站。

以上就介绍了unixtimestamp 通过PHP修改Linux或Unix口令的方法分享,包括了unixtimestamp方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!