ºìÁªLinuxÃÅ»§
Linux°ïÖú

UnixÖи³ÓèÓû§ÌØÊâȨÏÞ

·¢²¼Ê±¼ä:2006-07-30 09:53:23À´Ô´:ºìÁª×÷Õß:bear10214
ÔÚUnixϵͳÖУ¬¹ÜÀíÔ±ÍùÍù²»Ö»ÊÇÒ»¸öÈË£¬Èôÿλ¹ÜÀíÔ±¶¼ÓÃrootÉí·Ý½øÐйÜÀí¹¤×÷£¬¸ù±¾ÎÞ·¨ÅªÇå³þË­¸Ã×öʲô¡£ËùÒÔ×îºÃµÄ·½Ê½ÊÇ£º¹ÜÀíÔ±µ±ÏµÍ³µÄroot£¬È»ºó´´½¨Ò»Ð©ÆÕͨÓû§£¬·ÖÅäÒ»²¿·Öϵͳ¹ÜÀí¹¤×÷¸øËûÃÇ¡£
ÔÚUnixϵͳÖУ¬¹ÜÀíÔ±ÍùÍù²»Ö»ÊÇÒ»¸öÈË£¬Èôÿλ¹ÜÀíÔ±¶¼ÓÃrootÉí·Ý½øÐйÜÀí¹¤×÷£¬¸ù±¾ÎÞ·¨ÅªÇå³þË­¸Ã×öʲô¡£ËùÒÔ×îºÃµÄ·½Ê½ÊÇ£º¹ÜÀíÔ±µ±ÏµÍ³µÄroot£¬È»ºó´´½¨Ò»Ð©ÆÕͨÓû§£¬·ÖÅäÒ»²¿·Öϵͳ¹ÜÀí¹¤×÷¸øËûÃÇ¡£
ÎÒÃDz»¿ÉÒÔʹÓÃsuÈÃËûÃÇÖ±½Ó±ä³Éroot£¬ÒòΪÕâЩÓû§¶¼±ØÐëÖªµÀrootµÄÃÜÂ룬ÕâÖÖ·½·¨ºÜ²»°²È«£¬¶øÇÒÒ²²»·ûºÏÎÒÃǵķֹ¤ÐèÇó¡£Ò»°ãµÄ×ö·¨ÊÇÀûÓÃȨÏÞµÄÉèÖã¬ÒÀ¹¤×÷ÐÔÖÊ·ÖÀ࣬ÈÃÌØÊâÉí·ÝµÄÓû§³ÉΪͬһ¹¤×÷×飬²¢ÉèÖù¤×÷×éȨÏÞ¡£ÀýÈ磺ҪwwwadmÕâλÓû§¸ºÔð¹ÜÀíÍøÕ¾Êý¾Ý£¬Ò»°ãApache Web ServerµÄ½ø³ÌhttpdµÄËùÓÐÕßÊÇwww£¬Äú¿ÉÒÔÉèÖÃÓû§wwwadmÓëwwwΪͬһ¹¤×÷×飬²¢ÉèÖÃApacheĬÈÏ´æ·ÅÍøҳĿ¼/usr/local/httpd/htdocsµÄ¹¤×÷×éȨÏÞΪ¿É¶Á¡¢¿Éд¡¢¿ÉÖ´ÐУ¬ÕâÑùÊôÓڴ˹¤×÷×éµÄÿλÓû§¾Í¶¼¿ÉÒÔ½øÐÐÍøÒ³µÄ¹ÜÀíÁË¡£
µ«Õâ²¢²»ÊÇ×îºÃµÄ½â¾ö°ì·¨£¬ÀýÈç¹ÜÀíÔ±ÏëÊÚÓèÒ»¸öÆÕͨÓû§¹Ø»úµÄȨÏÞ£¬ÕâʱʹÓÃÉÏÊöµÄ°ì·¨¾Í²»ÊǺÜÀíÏë¡£ÕâʱÄúÒ²Ðí»áÏ룬ÎÒÖ»ÈÃÕâ¸öÓû§ÒÔrootÉí·ÝÖ´ÐÐshutdownÃüÁî¾ÍÐÐÁË¡£ÍêÈ«ÕýÈ·£¡¿ÉϧÔÚͨ³£µÄUnixϵͳÖÐÎÞ·¨ÊµÏÖÕâÒ»¹¦ÄÜ£¬²»¹ýÒѾ­ÓÐÁ˹¤¾ß¿ÉÒÔʵÏÖÕâÑùµÄ¹¦ÄÜ--sudo¡£
sudoͨ¹ýά»¤Ò»¸öÌØȨµ½Óû§ÃûÓ³ÉäµÄÊý¾Ý¿â½«ÌØȨ·ÖÅä¸ø²»Í¬µÄÓû§£¬ÕâЩÌØȨ¿ÉÓÉÊý¾Ý¿âÖÐËùÁеÄһЩ²»Í¬µÄÃüÁîÀ´Ê¶±ð¡£ÎªÁË»ñµÃijһÌØȨÏÓÐ×ʸñµÄÓû§Ö»Ðè¼òµ¥µØÔÚÃüÁîÐÐÊäÈësudoÓëÃüÁîÃûÖ®ºó°´ÕÕÌáʾÔÙ´ÎÊäÈë¿ÚÁÓû§×Ô¼ºµÄ¿ÚÁ²»ÊÇrootÓû§¿ÚÁ¡£ÀýÈ磬sudoÔÊÐíÆÕͨÓû§¸ñʽ»¯´ÅÅÌ£¬µ«ÊÇȴûÓи³ÓèÆäËûµÄrootÓû§ÌØȨ¡£
# gzip -d sudo-1.6.6.tar.gz£¨½âѹËõ£©
# tar xvf sudo-1.6.6.tar£¨½â°ü£©
# cd sudo-1.6.6
# ./configure
£¨ËѼ¯ÏµÍ³µÄ¸÷ÏîÐÅÏ¢£¬ÅäÖÃMakefileÎļþ£¬ÎªÊµ¼Ê±àÒë×ö×¼±¸£©
# make£¨±àÒ룩
# make install£¨°²×°£©
ÕâÊÇsudoÔ´´úÂë°æ±¾µÄ°²×°²½Ö裬ÄúÒ²¿ÉÒÔÈ¥ÏÂÔØsudoµÄ¶þ½øÖÆ°²×°°ü£¬ÈçSolarisµÄpackage°ü»òLinuxµÄrpm°üµÈ£¬ÕâÀï²»ÔÙ׸Êö¡£
sudo¹¤¾ßÓÉÎļþ/etc/sudoers½øÐÐÅäÖ㬸ÃÎļþ°üº¬ËùÓпÉÒÔ·ÃÎÊsudo¹¤¾ßµÄÓû§ÁÐ±í²¢¶¨ÒåÁËËûÃǵÄÌØȨ¡£Ò»¸öµäÐ͵Ä/etc/sudoersÌõÄ¿ÈçÏ£º
liming ALL=(ALL) ALL
Õâ¸öÌõĿʹµÃÓû§liming×÷Ϊ³¬¼¶Óû§·ÃÎÊËùÓÐÓ¦ÓóÌÐò£¬ÈçÓû§limingÐèÒª×÷Ϊ³¬¼¶Óû§ÔËÐÐÃüÁËûÖ»Ðè¼òµ¥µØÔÚÃüÁîÇ°¼ÓÉÏǰ׺sudo¡£Òò´Ë£¬ÒªÒÔrootÓû§µÄÉí·ÝÖ´ÐÐÃüÁîformat£¬liming¿ÉÒÔÊäÈëÈçÏÂÃüÁ
# sudo /usr/sbin/format
×¢Ò⣺ÃüÁîҪд¾ø¶Ô·¾¶£¬/usr/sbinĬÈϲ»ÔÚÆÕͨÓû§µÄËÑË÷·¾¶ÖУ¬¿ÉÒÔ¼ÓÈë´Ë·¾¶£ºPATH=$PATH:/usr/sbin;export PATH¡£
ÁíÍ⣬²»Í¬ÏµÍ³ÃüÁîµÄ·¾¶²»¾¡Ïàͬ£¬¿ÉÒÔʹÓÃÃüÁî¡°whereis ÃüÁîÃû¡±À´²éÕÒÆä·¾¶¡£
Õâʱ»áÏÔʾÏÂÃæµÄÊä³ö½á¹û£º
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these two things:
#1) Respect the privacy of others.
#2) Think before you type.
Password:
Èç¹ûlimingÕýÈ·µØÊäÈëÁË¿ÚÁÃüÁîformat½«»áÒÔrootÓû§Éí·ÝÖ´ÐС£
×¢Ò⣺ÅäÖÃÎļþ/etc/sudoers±ØÐëʹÓÃÃüÁî/usr/local/sbin/visudoÀ´±à¼­¡£Ö»Òª°ÑÏàÓ¦µÄÓû§Ãû¡¢Ö÷»úÃûºÍÐí¿ÉµÄÃüÁîÁбíÒÔ±ê×¼µÄ¸ñʽ¼ÓÈëµ½Îļþ/etc/sudoers²¢±£´æ¾Í¿ÉÒÔÉúЧ¡£
ÔÙ¿´Ò»¸öÀý×Ó£º
¹ÜÀíÔ±ÐèÒªÔÊÐí¡°baoshi¡±Óû§ÔÚÖ÷»ú¡°sun¡±ÉÏÖ´ÐС°reboot¡±ºÍ¡°shutdown¡±ÃüÁÔÚ/etc/sudoersÖмÓÈ룺
baoshi sun=/usr/sbin/reboot£¬/usr/sbin/shutdown
×¢Ò⣺ÃüÁîÒ»¶¨ÒªÊ¹Óþø¶Ô·¾¶£¬±ÜÃâÆäËûĿ¼µÄͬÃûÃüÁî±»Ö´ÐУ¬Ôì³É°²È«Òþ»¼¡£
È»ºó±£´æÍ˳ö£¬baoshiÓû§ÏëÖ´ÐÐrebootÃüÁîʱ£¬Ö»ÒªÔÚÌáʾ·ûÏÂÔËÐÐÏÂÁÐÃüÁ
$ sudo /usr/sbin/reboot
ÊäÈëÕýÈ·µÄÃÜÂ룬¾Í¿ÉÒÔÖØÆô·þÎñÆ÷ÁË¡£
Èç¹ûÄúÏë¶ÔÒ»×éÓû§½øÐж¨Ò壬¿ÉÒÔÔÚ×éÃûÇ°¼ÓÉÏ%£¬¶ÔÆä½øÐÐÉèÖã¬È磺
%cuug ALL=(ALL) ALL
ÁíÍ⣬»¹¿ÉÒÔÀûÓñðÃûÀ´¼ò»¯ÅäÖÃÎļþ¡£±ðÃûÀàËÆ×éµÄ¸ÅÄÓÐÓû§±ðÃû¡¢Ö÷»ú±ðÃûºÍÃüÁî±ðÃû¡£¶à¸öÓû§¿ÉÒÔÊ×ÏÈÓÃÒ»¸ö±ðÃûÀ´¶¨Ò壬ȻºóÔڹ涨ËûÃÇ¿ÉÒÔÖ´ÐÐʲôÃüÁîµÄʱºòʹÓñðÃû¾Í¿ÉÒÔÁË£¬Õâ¸öÅäÖöÔËùÓÐÓû§¶¼ÉúЧ¡£Ö÷»ú±ðÃûºÍÃüÁî±ðÃûÒ²ÊÇÈç´Ë¡£×¢ÒâʹÓÃÇ°ÏÈÒªÔÚ/etc/sudoersÖж¨Ò壺User_Alias¡¢Host_Alias¡¢Cmnd_AliasÏÔÚÆäºóÃæ¼ÓÈëÏàÓ¦µÄÃû³Æ¾Í¿ÉÒÔÁË£¬Ò²ÒÔ¶ººÅ·Ö¸ô¿ª£¬¾ÙÀýÈçÏ£º
Host_Alias SERVER=no1
User_Alias ADMINS=liming£¬baoshi
Cmnd_Alias SHUTDOWN=/usr/sbin/halt£¬/usr/sbin/shutdown£¬/usr/sbin/reboot
ADMIN SERVER=SHUTDOWN
ÔÙ¿´Õâ¸öÀý×Ó£º
ADMINS ALL=(ALL) NOPASSWD: ALL
±íʾÔÊÐíADMINS²»ÓÿÚÁîÖ´ÐÐÒ»ÇвÙ×÷£¬ÆäÖС°NOPASSWD:¡±ÏÒåÁËÓû§Ö´ÐвÙ×÷ʱ²»ÐèÒªÊäÈë¿ÚÁî¡£
sudoÃüÁ¿ÉÒÔ¼ÓÉÏһЩ²ÎÊýÖ´ÐУ¬Íê³ÉһЩ¸¨ÖúµÄ¹¦ÄÜ£¬È磺
$ sudo -l
»áÏÔʾ³öÀàËÆÕâÑùµÄÐÅÏ¢£º
User liming may run the following commands on this host:
(root) /usr/sbin/reboot
˵Ã÷Óû§liming±»rootÔÊÐíÖ´ÐÐ/usr/sbin/rebootÃüÁî¡£Õâ¸ö²ÎÊý¿ÉÒÔʹÓû§²é¿´×Ô¼ºÄ¿Ç°¿ÉÒÔÔÚsudoÖÐÖ´ÐÐÄÄЩÃüÁ·½±ãʹÓá£
ÔÚÃüÁîÌáʾ·ûϼüÈësudoÃüÁî»áÁгöËùÓвÎÊý£¬ÆäËûһЩ²ÎÊýÈçÏ£º
-V ÏÔʾ°æ±¾±àºÅ£»
-h ÏÔʾsudoÃüÁîµÄʹÓòÎÊý£»
-v ÒòΪsudoÔÚµÚÒ»´ÎÖ´ÐÐʱ»òÊÇÔÚN·ÖÖÓÄÚûÓÐÖ´ÐУ¨NÔ¤ÉèΪ5£©»áÎÊÃÜÂ룬Õâ¸ö²ÎÊýÊÇÖØÐÂ×öÒ»´ÎÈ·ÈÏ£¬Èç¹û³¬¹ýN·ÖÖÓ£¬Ò²»áÎÊÃÜÂ룻
-k ½«»áÇ¿ÆÈʹÓÃÕßÔÚÏÂÒ»´ÎÖ´ÐÐsudoʱѯÎÊÃÜÂ루²»ÂÛÓÐûÓг¬¹ýN·ÖÖÓ£©£»
-b ½«ÒªÖ´ÐеÄÖ¸Áî·ÅÔÚ±³¾°ÖÐÖ´ÐУ»
-p prompt ¿ÉÒÔ¸ü¸ÄÎÊÃÜÂëµÄÌáʾÓÆäÖÐ%u»á´ú»»ÎªÊ¹ÓÃÕßµÄÕ˺ÅÃû³Æ£¬%h»áÏÔʾÖ÷»úÃû³Æ£»
-u username/#uid ²»¼Ó´Ë²ÎÊý£¬´ú±íÒªÒÔrootµÄÉí·ÝÖ´ÐÐÖ¸Á¶ø¼ÓÁ˴˲ÎÊý£¬¿ÉÒÔÒÔusernameµÄÉí·ÝÖ´ÐÐÖ¸Á#uidΪ¸ÃusernameµÄUID£©£»
-s Ö´Ðл·¾³±äÊýÖÐµÄ SHELL ËùÖ¸¶¨µÄ shell £¬»òÊÇ /etc/passwd ÀïËùÖ¸¶¨µÄ shell £»
-H ½«»·¾³±äÊýÖеÄHOME£¨ËÞÖ÷Ŀ¼£©Ö¸¶¨ÎªÒª±ä¸üÉí·ÝµÄʹÓÃÕßµÄËÞÖ÷Ŀ¼£¨Èç²»¼Ó-u²ÎÊý¾ÍÊÇϵͳ¹ÜÀíÕßroot£©£»
ÒªÒÔϵͳ¹ÜÀíÕßÉí·Ý£¨»òÒÔ-u¸ü¸ÄΪÆäËûÈË£©Ö´ÐеÄÖ¸Áî¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 2 ÌõÆÀÂÛ

  1. mophis ÓÚ 2006-08-02 14:19:18·¢±í:

    ѧϰ£¡

  2. juyo ÓÚ 2006-08-02 08:48:57·¢±í:

    ѧϰ