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

UNIXϵͳϵÄÓû§ÏÞÖÆ

·¢²¼Ê±¼ä:2006-10-19 01:12:56À´Ô´:ºìÁª×÷Õß:pinkfirex
ÕªÒª
¡¡¡¡±¾ÎĽ«ÌÖÂÛÔÚLinuxϵͳÖУ¬ÏµÍ³¹ÜÀíÔ±ÈçºÎ¶ÔÔ¶³ÌÓû§ºÍ±¾µØÓû§½øÐÐÏÞÖÆ¡£ÏÞÖÆÓû§Äܹ»½øÐеIJÙ×÷£¬Äܹ»½µµÍϵͳÔâÊÜÄÚ²¿¹¥»÷µÄµÄ·çÏÕ¡£
¡¡¡¡ÔÚ´«Í³µÄUNIXϵͳÖУ¬Óû§µÄÏÞÖÆÊÇÓÉÎļþµÄȨÏÞ¡¢ÃÜÂëºÍÆäËü±ê×¼µÄUNIX·ÃÎÊ¿ØÖÆÍê³ÉµÄ¡£È¼¶ø£¬³ý´ËÖ®Í⻹ÐèÒª¸üΪÑϸñµÄÓû§ÏÞÖÆ£¬ÒÔ±ãÄܹ»¶ÔÓû§½øÐб£»¤ÒÔ¼°±£»¤ÏµÍ³²»ÊÜÌÔÆøÓû§µÄÆÆ»µ¡£±¾ÎĽ«ÌÖÂÛÔÚLinuxϵͳÖУ¬ÏµÍ³¹ÜÀíÔ±ÈçºÎ¶ÔÔ¶³ÌÓû§ºÍ±¾µØÓû§½øÐÐÏÞÖÆ¡£ÏÞÖÆÓû§Äܹ»½øÐеIJÙ×÷£¬Äܹ»½µµÍϵͳÔâÊÜÄÚ²¿¹¥»÷µÄµÄ·çÏÕ¡£µ«ÊÇ£¬¶ÔrootÓû§µÄȨÏÞÏÞÖƲ»ÔÚ±¾ÎĵÄÌÖÂÛ·¶Î§Ö®ÄÚ£¬¸ÐÐËȤµÄÈË¿ÉÒԲο¼ÀûÓÃcapabilityÌØÕ÷±£»¤ÏµÍ³µÄ°²È«¡£
1.Óû§ÏÞÖƵÄÄ¿±ê
¡¡¡¡¶ÔÓÚÓû§ÏÞÖÆ£¬²»Í¬µÄ»·¾³Óв»Í¬µÄÄ¿±ê£¬ÐèÒª²»Í¬µÄ¹¤¾ßʵÏÖ¡£ÀýÈ磬ÏÞÖƲ»¾­ÒâµÄÓû§Ê¹ÓÃUNIX shellºÍ·ÀÖ¹ÊìÁ·¹¥»÷ÕßÀûÓÃSUID³ÌÐò½øÐй¥»÷ÊDz»Í¬µÄ¡£¶øÇÒ£¬²»Í¬³Ì¶ÈµÄÏÞÖÆ¿ÉÄÜÐèÒª²»Í¬µÄ»·¾³£¬ÀýÈçÖ»ÔÊÐíʹÓÃijЩÓû§»òÕßÖ»¾Ü¾øʹÓÃijЩ³ÌÐò¡£
2.ÎļþµÄȨÏÞ
¡¡¡¡ÎÒÃÇÊ×ÏÈ´Ó×îÈõµÄÏÞÖÆ--UNIXȨÏÞ¿ªÊ¼¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬ÕâÒѾ­×ã¹»¡£Í¨¹ýÉèÖÃȨÏÞ£¬ÎÒÃÇ¿ÉÒÔ¿ØÖÆÄÄЩ¿ÉÖ´ÐÐÎļþ¿ÉÒÔÈÃÓû§Ê¹ÓᣳýÁËÄÇЩÔÊÐí·ÇÐÅÈÎÓû§Ö´ÐеijÌÐò£¬ÆäËüµÄ³ÌÐò¶¼²»Ó¦¸ÃÊÇËæ±ãÄĸöÓû§¶¼¿ÉÒÔÖ´Ðеģ»ËùÓÐÓû§¿ÉдµÄ·ÖÇø£¬ÀýÈ磺/tmpºÍ/home£¬¶¼Ó¦¸ÃʹÓÃnoexec²ÎÊý¼ÓÔØ(man mount)¡£×öµ½ÕâЩ£¬»ù±¾¿ÉÒÔ±£Ö¤ÏµÍ³µÄ°²È«¡£noexec²ÎÊýÄܹ»×èÖ¹Óû§ÏÂÔØ»òÕß½¨Á¢×Ô¼ºµÄ¿ÉÖ´ÐгÌÐò¡£Èç¹ûÒ»²¿·ÖÓû§ÐèÒª±È½Ï¸ßµÄȨÏÞ£¬ÎÒÃÇ¿ÉÒÔ°ÑÕâЩÓû§¼¯Öе½Ò»¸öÌØÊâµÄÓû§×飬°Ñ³ÌÐòÉèÖÃΪÔÊÐíÕâ¸ö×éÖ´ÐС£Í¨¹ýLinuxÎļþϵͳµÄÊôÐÔ(attribute)£¬ÀýÈ磺immutable¡¢append-onlyµÈ£¬»¹¿ÉÒÔ¶ÔrootȨÏÞ½øÐпØÖÆ£¬ÏêϸÇë²Î¿¼Îļþϵͳ°²È«-EXT2ÎļþϵͳµÄÊôÐÔ
3.ʹÓÃPAM½øÐÐȨÏÞÏÞÖÆ
¡¡¡¡ÁíÍâÒ»ÖÖ¼òµ¥(±È½Ï´àÈõ)µÄÏÞÖÆ¿ÉÒÔͨ¹ýLinuxϵͳ×ÊÔ´ÏÞÖÆʵÏÖ¡£ÏÞÖÆÓû§Äܹ»Ê¹ÓõÄϵͳ×ÊÔ´£¬¿ÉÒÔ×èÖ¹¶ñÒâÓû§Í¨¹ýһЩ±°ÁÓµÄÊֶΣ¬ÀýÈ磺fork´óÁ¿µÄ½ø³Ì¡¢Ìî³äÀ¬»øÎļþ£¬ÊµÏÖÏûºÄϵͳµÄ×ÊÔ´(´ÅÅ̿ռ䡢ÄÚ´æÒÔ¼°CPUʱ¼äµÈ)µÄÄ¿µÄ¡£LinuxµÄ²åÈëʽÈÏ֤ģ¿é(Pluggable Authentication Module))Äܹ»ÓÃÀ´½øÐÐϵͳ×ÊÔ´ÏÞÖÆ¡£±¾ÎÄÎÒÃǽ«Ö»ÊǽøÐÐÒ»°ãÐÔµÄÌÖÂÛ£¬ÏêÇéÇë²Î¿¼Securing and Optimizing Linux: RedHat Edition - A Hands-on Guide¡¢ Using Pam¡£
¡¡¡¡domain type item value
¡¡¡¡Ã¿¸öÓòµÄÒâÒåÈçÏÂ±í£º
domain
¿ÉÒÔÊÇ£º
? Ò»¸öÓû§Ãû£»
? Ò»¸öÓû§×éÃû£¬Ó﷨Ϊ@group£¬ÀýÈ磺@nixe0n£»
? »¹¿ÉÒÔÊÇͳÅä·û*£¬±íʾËùÓеÄÓû§

type
ÓÐÁ½ÖÖÀàÐÍ£º
? hard£ºÓɳ¬¼¶Óû§ºÍϵͳÄÚºËËù×öµÄÓ²ÐÔÏÞÖÆ£¬ÆÕͨÓû§ÎÞȨÐ޸ģ»
? soft£ºÓû§¿ÉÒÔ¸ù¾ÝÐèÒª£¬ÔÚhardµÄÏÞÖÆ·¶Î§ÄÚÐ޸ı»ÏÞÖƵÄ×ÊÔ´£¬¿ÉÒÔ¿´×÷ÊÇĬÈÏÉèÖã»

item
±»ÏÞÖƵÄÏîÄ¿°üÀ¨£º
? core£ºÏÞÖÆcoreÎļþµÄ´óС(ÒÔKBΪµ¥Î»)£»
? data£º½ø³ÌÊý¾Ý¶ÎµÄ×î´óÖµ(ÒÔKBΪµ¥Î»)£»
? fsize£ºÎļþµÄ×î´óÖµ(ÒÔKBΪµ¥Î»)£»
? memlock£º×î´óµÄ¼ÓËøÄÚ´æ¿Õ¼ä(µ¥Î»KB)£»
? nofile£º´ò¿ªÎļþµÄ×î´óÊýÁ¿£»
? rss£ºRSS(Resident Set Size)µÄ×î´óÖµ(µ¥Î»KB)£»
? ×î´óµÄÕ»Öµ(ÒÔKBΪµ¥Î»)£»
? cpu£º×î´óµÄCPUʱ¼ä£»
? nproc£ºÓû§µÄ×î´ó½ø³ÌÊýÁ¿£»
? as£ºµØÖ·¿Õ¼äÏÞÖÆ£»
? maxlogs£ºÕâ¸öÓû§×î´óµÄµÇ¼Êý£»
? priority£ºÓû§½ø³ÌµÄÓÅÏȼ¶£»

¡¡¡¡ÀýÈ磺
# =======================================
#
* soft core 0
* hard rss 10000
* hard nproc 20
¡¡¡¡Õâ¸öÅäÖÃÎļþÉèÖÃÓû§coreÎļþµÄ´óСÊÇ0£¬Óû§¿ÉÒÔ¸ù¾ÝÐèÒªÐ޸ģ»Ã¿¸ö½ø³ÌRSS×î´óÊÇ10000KB£»×î¶à¿ÉÒÔÔËÐÐ20¸ö½ø³Ì¡£
¡¡¡¡ÏÂÃæÕâ¸öÎļþÊÇÕë¶ÔÌØÊâÓû§×éfooËù×öµÄһЩÏÞÖÆ£º
@foo hard core 0
@foo hard rss 2000
@foo hard nproc 200
@foo hard fsize 100000
@foo hard nofile 100
@foo hard cpu 10
@foo hard priority 5
¡¡¡¡È»ºó£¬ÐèÒªÔÚ/etc/pam.d/loginÎļþÖмÓÈëÒÔÏÂÌõÄ¿£¬²ÅÄÜÊÇÏÞÖÆÉúЧ£º
¡¡¡¡Êµ¼ÊÉÏ£¬PAM¿ÉÒÔʵÏÖ¸üϸÁ£¶ÈµÄÏÔʾ£¬ÏêÇéÇë²Î¿¼RedHat¼¼Êõ°×ƤÊ飺Enhanced Console Access¡£
4.ÊÜÏÞshell
¡¡¡¡bash±¾ÉíÒ²ÓÐÒ»¶¨µÄÏÞÖƹ¦ÄÜ£¬¾ÍÊÇͨ¹ýÆä(ÊÜÏÞshell)restricted shell¹¦ÄÜ£¬Ëù×öµÄÏÞÖÆ°üÀ¨£º×èÖ¹Óû§¸Ä±äĿ¼ºÍ»·¾³±äÁ¿£»Öض¨ÏòÊä³ö£»Ê¹Óþø¶Ô·¾¶ÔËÐÐÃüÁʹÓÃexecÃüÁîºÍÆäËüһЩ²Ù×÷¡£Èç¹ûbashÊÇÒÔrbashΪÃûÆô¶¯£¬»òÕßʹÓÃ-rÑ¡ÏîÔËÐУ¬Ëü¾Í³ÆΪÊÜÏÞshell¡£ÊÜÏÞshellÄܹ»Ê¹ÏµÍ³»·¾³¸üºÃ¿ØÖÆ¡£Èç¹ûÆô¶¯ÊÜÏÞshell£¬ÒÔϲÙ×÷½«±»½ûÖ¹£º
ʹÓÃcdÃüÁîÇл»Ä¿Â¼£»
ÉèÖûòÕßÈ¡ÏûSHELL¡¢PATH¡¢ENV»òÕßBASH_ENV»·¾³±äÁ¿£»
ÒÔ¾ø¶Ô·¾¶ÔËÐÐÃüÁ
ʹÓþø¶Ô·¾¶Ö¸¶¨µÄÎļþÃû×÷ΪÄÚÖÃÃüÁî.µÄ²ÎÊý£»
ʹÓþø¶Ô·¾¶Ö¸¶¨µÄÎļþÃû×÷ΪÄÚÖÃÃüÁîhashµÄ²ÎÊý£»
ÔÚÆô¶¯Ê±£¬´Óshell»·¾³µ¼È뺯ÊýµÄ¶¨Ò壻
ÔÚÆô¶¯Ê±£¬½âÎöSHELLOPTSµÄÖµ£»
ʹÓÃ
>¡¢>|¡¢<>¡¢>&¡¢&>ºÍ>>
µÈÖض¨Ïò²Ù×÷Öض¨ÏòÊä³ö£»
ʹÓÃexecÃüÁîʹÆäËüµÄÃüÁî´úÌ浱ǰshell£»
ʹÓÃ-fºÍ-dÑ¡Ïî´ò¿ª/¹Ø±ÕÄÚÖÃÃüÁ
¶ÔÄÚÖÃÃüÁîʹÓÃ-pÑ¡Ï
¹Ø±ÕÊÜÏÞģʽ¡£
¡¡¡¡ÏÂÃæÎÒÃÇʵ¼ÊÊÔÑéһϣº
#adduser nixe0n
#passwd nixe0n
#ln -s /bin/bash /bin/rbash
#echo "/bin/rbash">>/etc/shells
#chsh -s /bin/rbash nixe0n
#cd ~nixe0n
#su nixe0n
$
¡¡¡¡È»ºó£¬Ö´ÐУº
¡¡¡¡$cd /
¡¡¡¡¾Í»á³öÏÖÒÔÏ´íÎó£º
¡¡¡¡rbash: cd: restricted
5.chroot
¡¡¡¡ÁíÍâÒ»ÖÖÏÞÖÆ·½Ê½ÊÇͨ¹ýchroot£¬°ÑÓû§ÏÞÖÆÔÚÒ»¸öÖ¸¶¨µÄĿ¼¡£ÕâÖÖ·½Ê½È·ÊµÄܹ»Ìṩһ¶¨³Ì¶ÈµÄ°²È«ÐÔ£¬Èç¹û²»ÄÜ»ñµÃrootȨÏÞ£¬Óû§½«ÎÞ·¨ÍÑÀë¼àÓü»·¾³¡£Òò´Ë£¬ÎªÁË×èÖ¹Óû§»ñµÃchrootedĿ¼֮ÍâĿ¼µÄ·ÃÎÊȨ£¬Ó¦¸ÃÉ÷ÖØÑ¡Ôñ¼àÓü»·¾³ÄÚµÄÓ¦ÓóÌÐò¡£
6.½áÂÛ
¡¡¡¡±¾ÎÄÎÒÃÇÌÖÂÛÁËLinuxϵͳ¶ÔÓû§µÄ¼¸ÖÖÏÞÖÆ·½Ê½£¬³ýÁËÒÔÉÏÕâЩ·½Ê½£¬»¹¿ÉÒÔʹÓÃLinuxÄں˵ÄcapabilityÌØÐÔ£¬ÏêÇéÇë²Î¿¼ÀûÓÃcapabilityÌØÐÔ¼ÓÇ¿LinuxϵͳµÄ°²È«ÐÔ¡£¾ßÌåµÄʹÓÃÒª¸ù¾Ýʵ¼ÊÇé¿öµÄÐèÒª£¬¼ÈÒª¿¼ÂÇϵͳµÄ°²È«ÐÔ£¬ÓÖÒª¹Ë¼°µ½ÊÇ·ñ¸øÓû§Ôì³É²»±ã¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. snqyss ÓÚ 2006-10-27 12:18:52·¢±í:

    ѧϰ