2006年11月01日 星期三 18:53
ÔÚLinuxÏÂʱ£¬Çл»µ½rootÓû§Ê±£¬ÏȼüÈësuÃüÁȻºóÌáʾÄãÊäÈëÃÜÂëʱ£¬¼üÈëÃÜÂë¡£ Õâ¸ö¹ý³ÌÈç¹ûÓÃpythonдһ¸ö³ÌÐò£¬Í¨¹ý´«²ÎÊýµÄÐÎʽ£¬Ö±½ÓÓÉÒ»°ãÓû§Çл»µ½rootÓû§£¬Ôõô´¦Àí£¿ Ö÷ÒªÊÇÈçºÎ¸øËüÃÜÂëÕâ¸ö²ÎÊý£¿ÎÒ²éÁËÏÂsuµÄ°ïÖú£¬ÈçÏ£º boyeestudio在beautown:~/linuxsoftware> su --help Usage: su [OPTION]... [-] [USER [ARG]...] Change the effective user id and group id to that of USER. -, -l, --login make the shell a login shell -c, --commmand=COMMAND pass a single COMMAND to the shell with -c -f, --fast pass -f to the shell (for csh or tcsh) -m, --preserve-environment do not reset environment variables -p same as -m -s, --shell=SHELL run SHELL if /etc/shells allows it --help display this help and exit --version output version information and exit A mere - implies -l. If USER not given, assume root. Report bugs to <bug-coreutils在gnu.org>. ÆäÖв¢Ã»ÓÐ×÷ΪÃÜÂëµÄ²ÎÊý¡£ Çë´ó´óÃÅÌáʾһÏ£¬Äܸø¸öʾÀý£¬·Ç³£¸Ðл£¡ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061101/ffc32512/attachment.html
2006年11月01日 星期三 19:33
On 11/1/06, boyeestudio <boyee118在gmail.com> wrote: > 在Linux下时,切换到root用户时,先键入su命令,然后提示你输入密码时,键入密码。 > 这个过程如果用python写一个程序,通过传参数的形式,直接由一般用户切换到root用户,怎么处理? 一般不允许进行口令的明文使用, 建议使用SSH2 的密匙形式,或是安装 sudo ,允许www 用户临时的运行某些系统命令就好 > 主要是如何给它密码这个参数?我查了下su的帮助,如下: > boyeestudio在beautown:~/linuxsoftware> su --help > Usage: su [OPTION]... [-] [USER [ARG]...] > Change the effective user id and group id to that of USER. > > -, -l, --login make the shell a login shell > -c, --commmand=COMMAND pass a single COMMAND to the shell with -c > -f, --fast pass -f to the shell (for csh or tcsh) > -m, --preserve-environment do not reset environment variables > -p same as -m > -s, --shell=SHELL run SHELL if /etc/shells allows it > --help display this help and exit > --version output version information and exit > > A mere - implies -l. If USER not given, assume root. > > Report bugs to <bug-coreutils在gnu.org>. > 其中并没有作为密码的参数。 > 请大大门提示一下,能给个示例,非常感谢! > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > -- """Time is unimportant, only life important! blog@ http://blog.zoomquiet.org/pyblosxom/ wiki@ http://wiki.woodpecker.org.cn/moin/ZoomQuiet douban@ http://www.douban.com/people/zoomq/ ____________________________________ Please use OpenOffice.org to stand for M$ office. Please use 7-zip to stand for WinRAR. You can get realy freedom from software. """
2006年11月01日 星期三 19:38
可以使用sudo去执行某个命令。并且,在 /etc/sudoers中添加一行 用户名 ALL=(ALL) NOPASSWD:ALL 这样该用户就可以随时用sudo命令来执行需要root权限才可以执行的命令,并且不 需要输入密码。 比如要执行 shutdown来关机。就可以这样用:sudo shutdown -h now On Wed, 2006-11-01 at 18:53 +0800, boyeestudio wrote: > 在Linux下时,切换到root用户时,先键入su命令,然后提示你输入密码时,键 > 入密码。 > 这个过程如果用python写一个程序,通过传参数的形式,直接由一般用户切换到 > root用户,怎么处理? > 主要是如何给它密码这个参数?我查了下su的帮助,如下: > boyeestudio在beautown:~/linuxsoftware> su --help > Usage: su [OPTION]... [-] [USER [ARG]...] > Change the effective user id and group id to that of USER. > > -, -l, --login make the shell a login shell > -c, --commmand=COMMAND pass a single COMMAND to the shell with > -c > -f, --fast pass -f to the shell (for csh or tcsh) > -m, --preserve-environment do not reset environment variables > -p same as -m > -s, --shell=SHELL run SHELL if /etc/shells allows it > --help display this help and exit > --version output version information and exit > > A mere - implies -l. If USER not given, assume root. > > Report bugs to <bug-coreutils在gnu.org>. > 其中并没有作为密码的参数。 > 请大大门提示一下,能给个示例,非常感谢! > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年11月02日 星期四 08:40
1.下面的代码是用telnet登陆到远程机器,然后su到root用户,对本地机器让HOST=
localhost即可,最后记得exit:
import telnetlib
tn = telnetlib.Telnet(HOST)
print tn.read_until("login: ")
tn.write(user + "\n")
print tn.read_until("Password: ")
tn.write(password + "\n")
print tn.read_until(PROMPT)
tn.write("su\n")
print tn.read_until("Password: ")
tn.write(root_password + "\n")
tn.write("exit\n")
print tn.read_all()
2.用pexpect更方便:
import pexpect
p=pexpect.spawn('su root')
p.expect('Password: ')
p.write('*****')
boyeestudio 写道:
> 在Linux下时,切换到root用户时,先键入su命令,然后提示你输入密码时,键
> 入密码。
> 这个过程如果用python写一个程序,通过传参数的形式,直接由一般用户切换到
> root用户,怎么处理?
> 主要是如何给它密码这个参数?我查了下su的帮助,如下:
> boyeestudio at beautown:~/linuxsoftware> su --help
> Usage: su [OPTION]... [-] [USER [ARG]...]
> Change the effective user id and group id to that of USER.
>
> -, -l, --login make the shell a login shell
> -c, --commmand=COMMAND pass a single COMMAND to the shell with -c
> -f, --fast pass -f to the shell (for csh or tcsh)
> -m, --preserve-environment do not reset environment variables
> -p same as -m
> -s, --shell=SHELL run SHELL if /etc/shells allows it
> --help display this help and exit
> --version output version information and exit
>
> A mere - implies -l. If USER not given, assume root.
>
> Report bugs to <bug-coreutils at gnu.org bug-coreutils at gnu.org>>.
> 其中并没有作为密码的参数。
> 请大大门提示一下,能给个示例,非常感谢!
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年11月02日 星期四 10:08
我也觉得sudo可能使更好地解决方案,如果可以安装的话,直接运行命令也方便。而 且 sudo -s 和 su 是一样的,也是新开一个root的shell。 你可以按照WangXinxi的方法,把你的用户变成nopassed得sudoer。或者,如果为安全 计不想变成NOPASSWD的sudoer,sudo -S 是直接从stdin读取密码的,你可以把密码管 道给sudo: echo "yourpassed" | sudo -S shutdown -h now On Wed, 01 Nov 2006 19:38:52 +0800, WangXinxi <wangxinxi at cs.hit.edu.cn> wrote: > 可以使用sudo去执行某个命令。并且,在 > /etc/sudoers中添加一行 > 用户名 ALL=(ALL) NOPASSWD:ALL > > 这样该用户就可以随时用sudo命令来执行需要root权限才可以执行的命令,并且不 > 需要输入密码。 > > 比如要执行 shutdown来关机。就可以这样用:sudo shutdown -h now > > On Wed, 2006-11-01 at 18:53 +0800, boyeestudio wrote: >> 在Linux下时,切换到root用户时,先键入su命令,然后提示你输入密码时,键 >> 入密码。 >> 这个过程如果用python写一个程序,通过传参数的形式,直接由一般用户切换到 >> root用户,怎么处理? >> 主要是如何给它密码这个参数?我查了下su的帮助,如下: >> boyeestudio at beautown:~/linuxsoftware> su --help >> Usage: su [OPTION]... [-] [USER [ARG]...] >> Change the effective user id and group id to that of USER. >> >> -, -l, --login make the shell a login shell >> -c, --commmand=COMMAND pass a single COMMAND to the shell with >> -c >> -f, --fast pass -f to the shell (for csh or tcsh) >> -m, --preserve-environment do not reset environment variables >> -p same as -m >> -s, --shell=SHELL run SHELL if /etc/shells allows it >> --help display this help and exit >> --version output version information and exit >> >> A mere - implies -l. If USER not given, assume root. >> >> Report bugs to <bug-coreutils at gnu.org>. >> 其中并没有作为密码的参数。 >> 请大大门提示一下,能给个示例,非常感谢! >> _______________________________________________ >> python-chinese >> Post: send python-chinese at lists.python.cn >> Subscribe: send subscribe to python-chinese-request at lists.python.cn >> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn >> Detail Info: http://python.cn/mailman/listinfo/python-chinese > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Zeuux © 2025
京ICP备05028076号