ÔõÑùÉèÖÃCentOSϵͳÒÔÏÞÖÆÓû§¶Ôϵͳ×ÊÔ´µÄ»á¼ûȨÏÞ
ÔõÑùÉèÖÃcentosϵͳÒÔÏÞÖÆÓû§¶Ôϵͳ×ÊÔ´µÄ»á¼ûȨÏÞ
СÐò£º
ÔÚÒ»¸ö¶àÓû§µÄϵͳÖУ¬ÎªÁ˱£»¤ÏµÍ³µÄÎȹÌÐÔºÍÇå¾²ÐÔ£¬ÐèÒª¶ÔÓû§µÄ»á¼ûȨÏÞ¾ÙÐÐÏÞÖÆ¡£CentOSÊÇÒ»ÖÖÊ¢ÐеÄLinux²Ù×÷ϵͳ£¬±¾ÎĽ«ÏÈÈÝÔõÑùÔÚCentOSϵͳÉÏÉèÖÃÓû§µÄ»á¼ûȨÏÞ£¬ÒÔʵÏÖ¶Ôϵͳ×ÊÔ´µÄÏÞÖÆ¡£
Ò»¡¢Óû§ºÍÓû§×éÖÎÀí
CentOSϵͳʹÓÃ/etc/passwdºÍ/etc/groupÎļþÀ´ÖÎÀíÓû§ºÍÓû§×é¡£ÎÒÃÇ¿ÉÒÔʹÓÃuseraddÏÂÁîÀ´½¨ÉèÐÂÓû§£¬Ê¹ÓÃgroupaddÏÂÁîÀ´½¨ÉèÐÂÓû§×é¡£
ʾÀý1£º½¨ÉèÐÂÓû§
sudo useradd -m -G users,testuser # ½¨ÉèÒ»¸öÃûΪtestuserµÄÓû§£¬²¢½«ÆäÌí¼Óµ½usersºÍtestuserÁ½¸öÓû§×éÖÐ
µÇ¼ºó¸´ÖÆ
¶þ¡¢Óû§È¨ÏÞÖÎÀí
ÔÚCentOSϵͳÖУ¬Óû§µÄȨÏÞÐÅÏ¢±»´æ´¢ÔÚ/etc/sudoersÎļþÖС£ÎÒÃÇ¿ÉÒÔͨ¹ýÐ޸ĸÃÎļþÀ´ÉèÖÃÓû§µÄsudoȨÏÞ¡£
ʾÀý2£ºÉèÖÃÓû§sudoȨÏÞ
sudo visudo # ʹÓÃvisudoÏÂÁîÀ´±à¼sudoersÎļþ
µÇ¼ºó¸´ÖÆ
ÔÚÎļþÖÐÕÒµ½²¢ÐÞ¸ÄÒÔÏÂÐУº
## Allow root to run any commands anywhere root ALL=(ALL) ALL ## Allow members of group sudo to execute any command # %sudo ALL=(ALL) ALL ## Allow members of group sudo to execute any command as any user %sudo ALL=(ALL:ALL) ALL
µÇ¼ºó¸´ÖÆ
ʾÀý3£ºÏÞÖÆÓû§sudoȨÏÞ
ÈôÊÇÎÒÃÇÏ£ÍûÏÞÖÆÓû§Ö»ÄÜÖ´ÐÐÌض¨µÄÏÂÁ¿ÉÒÔÌí¼ÓÏìÓ¦µÄȨÏÞÉèÖã¬ÈçÏÂËùʾ£º
user1 ALL=(ALL) /usr/bin/ls, /usr/bin/cat # Óû§user1¿ÉÒÔÖ´ÐÐlsºÍcatÏÂÁî user2 ALL=(ALL) NOPASSWD: /sbin/reboot # Óû§user2¿ÉÒÔÖ´ÐÐrebootÏÂÁÎÞÐèÃÜÂëÑéÖ¤
µÇ¼ºó¸´ÖÆ
Èý¡¢ÎļþȨÏÞÖÎÀí
CentOSϵͳʹÓÃȨÏÞλÀ´ÖÎÀíÎļþµÄ¶Á¡¢Ð´ºÍÖ´ÐÐȨÏÞ¡£ÎÒÃÇ¿ÉÒÔʹÓÃchmodÏÂÁîÀ´¸ü¸ÄÎļþµÄȨÏÞ¡£
ʾÀý4£º¸ü¸ÄÎļþËùÓÐÕߺÍȨÏÞ
sudo chown user1:group1 file.txt # ½«Îļþfile.txtµÄËùÓÐÕßÉèÖÃΪuser1£¬Óû§×éÉèÖÃΪgroup1 sudo chmod 600 file.txt # ÉèÖÃÎļþfile.txtµÄȨÏÞΪ600£¬¼´Ö»ÓÐËùÓÐÕßÓжÁдȨÏÞ
µÇ¼ºó¸´ÖÆ
ʾÀý5£ºÉèÖÃÎļþµÄ»á¼û¿ØÖÆÁÐ±í£¨ACL£©
»á¼û¿ØÖÆÁÐ±í£¨ACL£©ÔÊÐíÎÒÃÇΪÎļþºÍĿ¼ÉèÖÃϸÁ£¶ÈµÄ»á¼û¿ØÖÆ¡£ÎÒÃÇ¿ÉÒÔʹÓÃsetfaclÏÂÁîÀ´ÉèÖÃÎļþµÄACL¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪȷ±£Îļþϵͳ֧³ÖACL¡£ÎÒÃÇ¿ÉÒÔÔÚ/etc/fstabÎļþÖÐÕÒµ½ÏìÓ¦µÄÎļþϵͳÌõÄ¿£¬²¢È·±£aclÑ¡Ïî±»ÆôÓá£ÀýÈ磺
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / ext4 defaults,acl 0 0
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃÇ¿ÉÒÔʹÓÃsetfaclÏÂÁîÀ´ÉèÖÃÎļþµÄACL£¬ÈçÏÂËùʾ£º
sudo setfacl -m u:user1:rw file.txt # ¸øuser1ÊÚÓèfile.txtµÄ¶ÁдȨÏÞ sudo setfacl -m u:user2:r file.txt # ¸øuser2ÊÚÓèfile.txtµÄ¶ÁȨÏÞ sudo getfacl file.txt # Éó²éÎļþfile.txtµÄACLÉèÖÃ
µÇ¼ºó¸´ÖÆ
½áÂÛ£º
ͨ¹ýÊÊÍâµØÉèÖÃCentOSϵͳ£¬ÎÒÃÇ¿ÉÒÔÏÞÖÆÓû§¶Ôϵͳ×ÊÔ´µÄ»á¼ûȨÏÞ£¬±£»¤ÏµÍ³µÄÎȹÌÐÔºÍÇå¾²ÐÔ¡£±¾ÎÄÏÈÈÝÁËÓû§ºÍÓû§×éÖÎÀí¡¢Óû§È¨ÏÞÖÎÀíºÍÎļþȨÏÞÖÎÀíµÄ³£ÓÃÒªÁ죬²¢ÌṩÁËÏìÓ¦µÄ´úÂëʾÀý¡£Ï£Íû±¾ÎÄ¿ÉÒÔ×ÊÖú¶ÁÕ߸üºÃµØÉèÖÃCentOSϵͳ£¬²¢ÊµÏÖ¶Ôϵͳ×ÊÔ´µÄÓÐÓÃÖÎÀí¡£
ÒÔÉϾÍÊÇÔõÑùÉèÖÃCentOSϵͳÒÔÏÞÖÆÓû§¶Ôϵͳ×ÊÔ´µÄ»á¼ûȨÏÞµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡