my note: ubuntu server security
DESCRIPTION
Having read an article on the internet (url at the end of the article), I 'd like to make a note for my future use and also share it with you.It's about the security again, but this time for server.The nice thing for the article was that it kept the story concise enough for a beginner like me to see it as a whole.It also guided me indirectly what to explore next! Thanks the authors.BTW, the last word on the article impressed me. So, I made some excerpts without translation and place them at the end of my note.TRANSCRIPT
My note on Ubuntu Server Security Page 1 S. Saengamnatdej
My Note: Ubuntu Server Security
สมชาย แสงอำานาจเดช3 กนยายน 2553
เนอหาในบนทกนนาจะเปนจดเรมตนสำาหรบการเรยนรเกยวกบความปลอดภยของเซรฟ เวอรของอบนทหรอในระบบทคลายยนกซตางๆ บนทกยอเฉพาะสาระสำาคญจากเนอหาทปรากฏ
ในอางองทายบนทกซงเปนบทความทตดขอความมาจากหนงสอของผเขยนอนอกตอหนง
ก. บรหารจดการบญชผใชงาน
1. การเพม user เขาในกลม admin ใสชอ (username) ในคำาสงตอไปน$ sudo adduser username admin
2. การลบชอผใช เปลยน adduser เปน deluser3. ใช $ visudo ในการกำาหนดสทธ (superuser privileges) ในไฟล /etc/sudoers
ข. ความปลอดภยของระบบไฟล
ตนแบบความปลอดภยของไฟลในระบบทคลายยนกซเปนมาตรฐานเหมอนกนเรยกวา แบบ POSIX model การอนญาตการเขาถงไฟลและไดเรกตอรม 3 ชนด เจาของ (owner), กลม (group),
และอนๆ (other) ทำาการแบงพารตชนภายในไดเรกตอรตางๆ อยางนอยกไดเรกตอรตอไปน /home, /tmp และ
/var ตวเลอกใชทนาสนใจมดงน
nodev ตวเลอกนจะไมอนญาตใหใชหรอสรางไฟล device เฉพาะขนมา ซงบางอยางนนเสยงตอ
ความปลอดภย
nosuid การใหใครกตามสงรนโปรแกรม (execute) ไดในสทธของ admin หรอผใชอน (โดยใช
setuid(suid) หรอ setgid) ทำาใหเขาไดเรกตอรทม binaries ของระบบ นอกจากจะไมมความจำาเปน แลวยงลดความปลอดภย เพราะถาผใชใดเขาไปไดอาจสรางหรอเขาไบนารแลวเปลยนแปลงระบบ
ใหเออตอเขาทนท (compromised) ดงนนการใชตวเลอกจะปองกน
noexec ถาระบบไฟลกำาหนดดวยตวเลอกน จะปองกนไมใหผใชรนอะไรไดในไดเรกตอรนน
noatime ตวเลอกน จะทำาใหระบบไฟลไมทำาบนทกไฟลทเขามาครงลาสด แตถาใชแบบไมเลอกอาจ
ลดความปลอดภยเนองจากไปลดขอมลในกรณทมการฝาระบบความปลอดภยเขามาโดยเฉพาะ กรณทตองตรวจสอบคอมพวเตอร (computer forensics)
My note on Ubuntu Server Security Page 2 S. Saengamnatdej
การจะเลอกวาในไดเรกตอรท mount ไหนจะใชพารตชนคอนขางตดสนใจยาก การเลอกท เหมาะสมอาจจะเกดหลงจากไดใชและเกดความคนเคยแลว สำาหรบตวอยาง การเลอก mount และ
partition ขนตนมดงน /home-nosuid, nodev /tmp-noatime, noexec, nodev, nosuid /var-noexec, nodev, nosuid
การจำากดทรพยากรของระบบ
ปกตลนกซยอมใหผใชทงหนวยความจำา หรอใชโปรเซส (process) ไดเตมทไมจำากด อาจทำาใหมผใชงานบางคนใชหนวยความจำาทงหมดหรอปลอยใหโปรเซสวงวนไมจบทำาใหระบบทำางาน
ไมไดนานเปนวนาท สามารถตงการจำากดการใชโดยไปแกไขไฟล /etc/security/limits.confดวยคำาสง
$ sudoedit /etc/security/limits.conf
ซงรายละเอยดการตงคาอยในไฟลนน ( ท comment) อยางนอยอาจตงท nproc limit และ /data/_memlock/rss
ตวอยาง กำาหนดการจำากดทรพยากรดงนas 2097152data 131072
memlock 131072rss 1013352
hard nproc 128 หมายความวา ผใชทวไปจะรนได 128 โปรเซส มพนทสงสดเทากบ 2 GB มขนาดขอมลสงสด
และเนอทความจำาทลอคไวเทากบ 128 MB และเนอทสงสดสำาหรบ resident set size เทากบ 1 GB ถาตองการแบงโควตาพนทใหผใช ใหตดตง quota package
ไฟลลอกของระบบ (System Log Files)
ไฟลเหลานเปนไฟลทมประโยชนมากสำาหรบผดแลระบบ ถาดอยางระมดระวงจะรไดลวงหนาวาเมอไรบางสงผดปกตเกดในระบบและจะสามารถแกปญหาสวนใหญไดกอนทปญหาจะเพมขน ผดแลระบบมกใชโปรแกรม (log processing software) ทตงคาใหเตอนเมอเกดสงผดปกตขน
หรออาจเขยนโปรแกรมขนเองดวยภาษา Perl และ Python ไฟลลอกมกจะเกบท /var/log ซงหลงจากตดตงเซรฟเวอรแลวจะเรมมไฟลลอกเพมขนใน
ไดเรกตอรน ไฟลจำานวนมากถกอดเกบดวย gzip ( สงเกตนามสกลไฟลเปน .gz)
ไฟลลอกทสำาคญมดงน /var/log/syslog - general system log • /var/log/auth.log - system authentication logs • /var/log/mail.log - system mail logs • /var/log/messages - general log messages • /var/log/dmesg - kernel ring buffer messages, usually since system bootup
My note on Ubuntu Server Security Page 3 S. Saengamnatdej
เครองมอใชกบไฟลลอก1. คำาสง tail เพอพมพ 10 บรรทดสดทายของไฟลลอก ทำาใหพอรวามอะไรเกดขนทายสดท
บนทกในไฟลนน เชน
$ tail /var/log/syslog
ถาใสตวเลอกหรอพารามเตอร -f จะเปน follow mode ทโปรแกรมจเปดไฟลแลวรายงานสงท เปลยนแปลงทจอเครองทนททกำาลงเกดขน
2. คำาสง zgrep, zcat, และ zless ทำางานเชนเดยวกบคำาสง grep, cat, และ less ทใชกบไฟล gzip-compressed files
ตวอยาง ถาตองการใหแสดงบรรทดใน ลอกชนด compressed log ทมคำาวา "warthog" อยจะใชคำาสง
$ zgrep -i warthog /var/log/*.gz
ความปลอดภยในเครอขาย (Network security)
ใชคำาสง iptables โดยเนอหาสามารถคนจากอนเตอรเนต เรยนรการใชคำาสงนมประโยชน มากเพราะชวยตงคาความปลอดภยของเครอขายบนเครองลนกซ และชวยทำาใหการเรยนรระบบ
firewall ของระบบ OS อนๆไดงายขนตวอยาง
$ sudo iptables -A INPUT -s www.slashdot.org -j DROP
ขอคดทงทาย"Securing systems isn't about making it impossible for a breach to occur. It's about making the breach so difficult that it's not worth it to the attacker." However, an attack also depends on a cost/benefit point of view.
"Security is also neat because, as a concept, it permeates the entire idea space of computer science. Getting really good at security requires incredibly deep understanding of the inner workings of computer systems, which has the nonobvious advantage that if you're trying to get a deep understanding of computer systems but don't know where to start, you can start with security and simply follow the trail. Use this to your advantage!"
ReferenceComputerworld. Tips on keeping your Ubuntu Linux server secure. August 24, 2006. available at http://www.computerworld.com/s/article/9002691/Tips_on_keeping_your_Ubuntu_Linux_server_secure accessed Sep. 2, 2010.(This article is excerpted from The Official Ubuntu Book by Benjamin Mako Hill, Jono Bacon, Corey Burger, Jonathan Jesse and Ivan Krstic, copyright Prentice Hall. Reprinted with permission of Prentice Hall, all rights reserved. )