SlideShare a Scribd company logo
1 of 28
Download to read offline
Linux Server Admin


    Elastichosts
   Server Admin 3
     Chatchai J

    2013-02-04
ก่อนอื่น
●   ผมเคยทำำให้คุณดูเป็ นตัวอย่ำง

●   กำรใช้งำน MySQL กำำหนด password สำำหรับ
    MySQL admin account
    login: root
    password: root
●   นั่นเป็ นสิ่งทีผิด
                   ่
ก่อนอื่น (ต่อ)
●   เป็ นตัวอย่ำงที่ไม่ดี เป็ นสิ่งที่ไม่สมควรทำำ

●   เป็ นควำมผิดของผมเอง

●   ขอโทษด้วยครับ
Password
●   นับแต่นเป็ นต้นไป
           ี้

●   ขอให้ใช้ secure password

●   สำำหรับ ทุกกรณี
ปั ญหำของ secure password
●   ถ้ำใช้ควำมจำำ สำำหรับจำำ password โดยตรง

    Secure password จะจำำยำก
    ทำำให้เลือก password ที่จำำง่ำย

    ทำำให้ถูกโจมตีได้ง่ำย

●   เพรำะ ฉะนั้น ให้จดลงใน เศษกระดำษ

●   เก็บไว้ในกระเป๋ ำสตำงค์ (หลีกเลี่ยงกำรเก็บเป็ นไฟล์/email)
วิธีกำรสร้ำงและเก็บ password
●   เครื่องมือ pwgen, sharutils
    $ sudo apt­get install pwgen sharutils
●   สร้ำง password ยำว 12 ตัวอักษร โดยใช้ pwgen
    $ pwgen ­s 12 1
●   จะได้ string ขนำด 12 ตัวอักษร ซึ่งสำมำรถเอำไปใช้เป็ น
    password ได้ทนที
                 ั
password (cont)
●   ซึ่ง ไม่แนะนำำ ให้ใช้ อย่ำงนั้น

●   เรำต้องกำร password จำำนวนหลำยชุด
    –   root's password
    –   admin's (e.g. – cj) password
    –   mysql admin's password
●   ทั้งหมดควรจะเป็ น password คนละตัวกัน

●   ถ้ำเกิด password ตัวใดตัวหนึ่ง หลุดรอดไป (ถ้ำไม่ใช่ root
    password) ทีเหลือก็จะยังปลอดภัย
                ่
password (cont)
●   แต่ถ้ำจะสร้ำง password ใหม่ท้ ังหมด สำำหรับ
    แต่ละ account ก็จะต้องกำร กำรจดบันทึก
    จำำนวนมำก (password อะไร สำำหรับ อะไร)

●   หรือไม่ หลำยคน ก็จะเลือกใช้ password
    เดียวกัน สำำหรับแก้ปัญหำ ซึ่งไม่ดี
password (cont)
●   วิธีกำร ใช้ string ทีได้มำ เป็ นชุด string ตั้งต้น
                         ่

●   แล้วสร้ำง password ทีเหลือ จำก string ชุดนั้น
                         ่

●   โดยใช้วิธีกำรร่วมกัน กำรจดบันทึก

●   แนะนำำให้ใช้ string เริมต้นขนำด 16 อักษร
                           ่

●   แต่ถ้ำยำวกว่ำนั้นได้กยิ่งดี
                         ็
    $ pwgen ­s 16 1
password (cont)
    $ pwgen 16 1
    sie3ooF5ahWei0ee 
●   วิธีกำรจด ใน กระดำษ
         s i e 3
         o o F 5
         a h W e
         i 0 e e
password (cont)
●   สำำหรับกำรป้ องกันโจมตีแบบ brute force attack
    ปั จจุบัน ควำมยำวไม่ควรตำ่ำกว่ำ 10

●   สมมติเลือก password ยำว 12 ตัวอักษร สำำหรับ
    ทุกกรณี

●   เลือก pattern ของ password สำำหรับ แต่ละ
    account
password (cont)
password (cont)
●   จะได้
        root's password = “sie35eee0iao”
        admin's password = “sie35FooahWe”
        mysql's password = “sie3FhiOeewo”
●   Password จะมีควำม secure สูงขึ้น ถ้ำ

    –   ไม่ได้เริ่มต้นที่บรรทัดแรก

    –   ไม่ได้เรียงจำกซ้ำยไปขวำ
และที่สำำคัญ
●   อย่ำทำำกระดำษทีจดเอำไว้หำย
                   ่

●   password ทีสร้ำงขึ้นด้วย pwgen เป็ นแบบ pseudo-random
               ่

●   ซึ่งในกรณีนี้ เทียบเท่ำกับ true random

●   ไม่สำมำรถก้คนมำได้อีก
               ู ื

●   ถ้ำกระดำษทีจดไว้หำย และ ลืม password
               ่

●   ก็จะไม่มทำงก้คนมำได้
            ี    ู ื
ถ้ำต้องกำรกู้คืน
●   เปลียนวิธีกำรสร้ำง string เริมต้นจำกกำรใช้ pwgen
        ่                        ่

●   เป็ นวิธีกำรอื่น ซึ่ง

    –   สำมำรถทำำซำ้ำได้ และ

    –   ได้ผลเหมือนเดิม

●   แต่ผลลัพธ์จะต้องใกล้เคียงกับกำร

●   random เพื่อสร้ำง string
message digest
●   เครื่องมือบน linux สำำหรับ digest message
    –   md5sum
    –   shasum -a {1,224,256,384,512}
●   สร้ำง sum string จำก message ใดๆ

●   ถ้ำ message เปลี่ยนไปผล sum จะเปลี่ยนไป
ทดลอง
●   กำรทดลอง ทั้งหมด ให้ทำำบน VM บน local (notebook)
    $ echo “a” | md5sum
    $ echo “hello” | md5sum
    $ echo “Hello” | md5sum
    $ echo “How are you doing?” | md5sum
    $ cat /etc/passwd | md5sum
●   เปลียนจำก md5sum เป็ น shasum ­a 1
        ่

●   หรือ shasum ­a 224 (เป็ นต้น)
message digest
$ echo "a" | md5sum
60b725f10c9c85c70d97880dfe8191b3  ­
$ echo "a" | sha1sum
3f786850e387550fdab836ed7e6dc881de23001b  ­
$ echo "a" | shasum ­a 256
87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7  ­
$ echo "a" | shasum ­a 512
162b0b32f02482d5aca0a7c93dd03ceac3acd7e410a5f18f3fb990fc958ae0df6f32233
b91831eaf99ca581a8c4ddf9c8ba315ac482db6d4ea01cc7884a635be  ­


$ echo "hello" | md5sum
b1946ac92492d2347c6235b4d2611184  ­
$ echo "Hello" | md5sum
09f7e02f1290be211da707a266f153b3  ­
เพิ่ม security
●   ตัวอักษรที่ได้จำก XXXsum จะมี 'a'-'z','0'-'9'

●   ถ้ำมีควำมยำวมำกพอ ก็จะเพิ่ม security ได้

●   แต่เรำสำมำรถสร้ำง output string ที่มีตัวอักษร หลำก
    หลำยมำกขึ้นได้ โดยกำรใช้ เครื่องมืออื่นเพิ่ม
    –   base64
    –   uuencode
เพิ่ม security (ต่อ)
     $ echo “a” | shasum ­a 256 | base64
     $ echo “a” | shasum ­a 512 | uuencode x


$ echo "a" | shasum ­a 256 | base64
ODc0MjhmYzUyMjgwM2QzMTA2NWU3YmNlM2NmMDNmZTQ3N
TA5NjYzMWU1ZTA3YmJkN2EwZmRlNjBjNGNmMjVjNyAgLQ
o=
$ echo "a" | shasum ­a 512 | uuencode x
begin 644 x
M,38R8C!B,S)F,#(T.#)D­6%C83!A­V,Y,V1D,#­C96%C,V%C9#=E­#$P835F
M,3AF,V9B.3DP9F,Y­3AA93!D9C9F,S(R,S­B.3$X,S%E868Y.6­A­3@Q83AC
J­&1D9CEC.&)A,S$U86,T.#)D8C9D­&5A,#%C8S<X.#1A­C,U8F4@("T*
`
end
วิธกำรเอำไปใช้
                           ี
●   เก็บ “string” เริ่มต้น (“a”, “hello”) เป็ นควำมลับ สูงสุด

●   เก็บ วิธกำร digest และ encode ทีเลือกใช้เป็ นควำมลับ
            ี                       ่

●   เลือกตำำแหน่งเริ่มต้นของ output string ทีเอำมำใช้เป็ นควำมลับ (ไม่
                                             ่
    จำำเป็ นจะต้องเริ่มที่ 1)

●   แต่ท้ งหมดนั้น จะต้องไม่ลม
          ั                  ื

●   ถ้ำลืม วิธีกำรทีว่ำมำทั้งหมด ก็ไม่มประโยชน์ ให้กลับไปใช้
                    ่                  ี
    pwgen -s 16 1 แทนก็จะไม่เสียเวลำ
วิธีกำรเอำไปใช้ (ต่อ)
●   ถ้ำจำำเป็ น

●   แยกจด / แยกเก็บ

●   string เริ่มต้น, วิธีกำร sum, วิธีกำร encode

      จดใส่กระดำษ เก็บร่วมกับ ใบสูตบัตร, เอกสำร
                                   ิ
      สำำคัญอื่นๆ ที่ “หำยไม่ได้” แต่ นำนๆใช้ที
วิธีกำรเอำไปใช้ (ต่อ)
●   output string สำำหรับ password
    จดใส่กระดำษ เก็บในกระเป๋ ำสตำงค์ เก็บบัตรประจำำตัวประชำชน หรือ
    เอกสำรสำำคัญ ชนิดอื่นๆ ทีใช้งำนบ่อย
                             ่

●   pattern ของกำรเลือก password จำก output string ที่เก็บในกระเป๋ ำสตำงค์


    จำำ – ใช้งำนบ่อย ไม่จำำเป็ นต้องเปลี่ยนบ่อย จะจำำได้เอง
หมำยเหตุ:
●   ทุกคำำสั่งที่คุณพิมพ์ บน linux และใช้งำน bash
    เป็ น shell จะเก็บอยู่ใน .bash_history

●   เมื่อ logout

●   กำำหนดโดย HISTFILE
    $ echo $HISTFILE
หมำยเหตุ: (cont)
●   วิธีกำรไม่ให้บันทึก
    $ HISTFILE=/dev/null
    $ exit
●   เพื่อให้ string เริ่มต้น, วิธกำร digest, วิธีกำร
                                 ี
    encode เป็ นควำมลับ
กำรเปลียน password
                  ่
●   password root และ admin account ใช้
      $ sudo passwd root
      $ sudo passwd admin
กำรเปลียน password (cont)
              ่
●   สำำหรับ mysql admin's password
      term1:~$ sudo service mysql stop
      term1:~$ sudo mysqld –skip­grant­tables

      term2:~$ mysql
      term2 mysql> update mysql.user 
            set password=PASSWORD('*************')
            where user='root';
      term2 mysql> exit;

      term1:~$ CTRL+''
กำรเปลียน password (cont)
              ่
●   คำำสั่งที่ใช้บน mysql client จะเก็บไว้ใน
    .mysql_history

      $ cat .mysql_history
      $ rm ­f .mysql_history

More Related Content

Viewers also liked

Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutesLarry Cai
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerJérôme Petazzoni
 
A Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersA Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersJérôme Petazzoni
 
Why Docker
Why DockerWhy Docker
Why DockerdotCloud
 
Docker introduction
Docker introductionDocker introduction
Docker introductiondotCloud
 
Docker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCSDocker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCSFrank Munz
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of EverythingCharbel Zeaiter
 

Viewers also liked (9)

Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
Ch09 mail-systems-part2
Ch09 mail-systems-part2Ch09 mail-systems-part2
Ch09 mail-systems-part2
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with Docker
 
A Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersA Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things Containers
 
Why Docker
Why DockerWhy Docker
Why Docker
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCSDocker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCS
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of Everything
 

More from Chatchai Jantaraprim (7)

Ch08 mail-systems
Ch08 mail-systemsCh08 mail-systems
Ch08 mail-systems
 
Ch07 bind9-part2
Ch07 bind9-part2Ch07 bind9-part2
Ch07 bind9-part2
 
Ch06 bind9
Ch06 bind9Ch06 bind9
Ch06 bind9
 
Ch04 linux-hosting-vps
Ch04 linux-hosting-vpsCh04 linux-hosting-vps
Ch04 linux-hosting-vps
 
Ch05 name-services
Ch05 name-servicesCh05 name-services
Ch05 name-services
 
Ch03 domain-registration
Ch03 domain-registrationCh03 domain-registration
Ch03 domain-registration
 
Ch02 administrators-tasks
Ch02 administrators-tasksCh02 administrators-tasks
Ch02 administrators-tasks
 

Ch17 secure-password

  • 1. Linux Server Admin Elastichosts Server Admin 3 Chatchai J 2013-02-04
  • 2. ก่อนอื่น ● ผมเคยทำำให้คุณดูเป็ นตัวอย่ำง ● กำรใช้งำน MySQL กำำหนด password สำำหรับ MySQL admin account login: root password: root ● นั่นเป็ นสิ่งทีผิด ่
  • 3. ก่อนอื่น (ต่อ) ● เป็ นตัวอย่ำงที่ไม่ดี เป็ นสิ่งที่ไม่สมควรทำำ ● เป็ นควำมผิดของผมเอง ● ขอโทษด้วยครับ
  • 4. Password ● นับแต่นเป็ นต้นไป ี้ ● ขอให้ใช้ secure password ● สำำหรับ ทุกกรณี
  • 5. ปั ญหำของ secure password ● ถ้ำใช้ควำมจำำ สำำหรับจำำ password โดยตรง Secure password จะจำำยำก ทำำให้เลือก password ที่จำำง่ำย ทำำให้ถูกโจมตีได้ง่ำย ● เพรำะ ฉะนั้น ให้จดลงใน เศษกระดำษ ● เก็บไว้ในกระเป๋ ำสตำงค์ (หลีกเลี่ยงกำรเก็บเป็ นไฟล์/email)
  • 6. วิธีกำรสร้ำงและเก็บ password ● เครื่องมือ pwgen, sharutils $ sudo apt­get install pwgen sharutils ● สร้ำง password ยำว 12 ตัวอักษร โดยใช้ pwgen $ pwgen ­s 12 1 ● จะได้ string ขนำด 12 ตัวอักษร ซึ่งสำมำรถเอำไปใช้เป็ น password ได้ทนที ั
  • 7. password (cont) ● ซึ่ง ไม่แนะนำำ ให้ใช้ อย่ำงนั้น ● เรำต้องกำร password จำำนวนหลำยชุด – root's password – admin's (e.g. – cj) password – mysql admin's password ● ทั้งหมดควรจะเป็ น password คนละตัวกัน ● ถ้ำเกิด password ตัวใดตัวหนึ่ง หลุดรอดไป (ถ้ำไม่ใช่ root password) ทีเหลือก็จะยังปลอดภัย ่
  • 8. password (cont) ● แต่ถ้ำจะสร้ำง password ใหม่ท้ ังหมด สำำหรับ แต่ละ account ก็จะต้องกำร กำรจดบันทึก จำำนวนมำก (password อะไร สำำหรับ อะไร) ● หรือไม่ หลำยคน ก็จะเลือกใช้ password เดียวกัน สำำหรับแก้ปัญหำ ซึ่งไม่ดี
  • 9. password (cont) ● วิธีกำร ใช้ string ทีได้มำ เป็ นชุด string ตั้งต้น ่ ● แล้วสร้ำง password ทีเหลือ จำก string ชุดนั้น ่ ● โดยใช้วิธีกำรร่วมกัน กำรจดบันทึก ● แนะนำำให้ใช้ string เริมต้นขนำด 16 อักษร ่ ● แต่ถ้ำยำวกว่ำนั้นได้กยิ่งดี ็ $ pwgen ­s 16 1
  • 10. password (cont) $ pwgen 16 1 sie3ooF5ahWei0ee  ● วิธีกำรจด ใน กระดำษ s i e 3 o o F 5 a h W e i 0 e e
  • 11. password (cont) ● สำำหรับกำรป้ องกันโจมตีแบบ brute force attack ปั จจุบัน ควำมยำวไม่ควรตำ่ำกว่ำ 10 ● สมมติเลือก password ยำว 12 ตัวอักษร สำำหรับ ทุกกรณี ● เลือก pattern ของ password สำำหรับ แต่ละ account
  • 13. password (cont) ● จะได้ root's password = “sie35eee0iao” admin's password = “sie35FooahWe” mysql's password = “sie3FhiOeewo” ● Password จะมีควำม secure สูงขึ้น ถ้ำ – ไม่ได้เริ่มต้นที่บรรทัดแรก – ไม่ได้เรียงจำกซ้ำยไปขวำ
  • 14. และที่สำำคัญ ● อย่ำทำำกระดำษทีจดเอำไว้หำย ่ ● password ทีสร้ำงขึ้นด้วย pwgen เป็ นแบบ pseudo-random ่ ● ซึ่งในกรณีนี้ เทียบเท่ำกับ true random ● ไม่สำมำรถก้คนมำได้อีก ู ื ● ถ้ำกระดำษทีจดไว้หำย และ ลืม password ่ ● ก็จะไม่มทำงก้คนมำได้ ี ู ื
  • 15. ถ้ำต้องกำรกู้คืน ● เปลียนวิธีกำรสร้ำง string เริมต้นจำกกำรใช้ pwgen ่ ่ ● เป็ นวิธีกำรอื่น ซึ่ง – สำมำรถทำำซำ้ำได้ และ – ได้ผลเหมือนเดิม ● แต่ผลลัพธ์จะต้องใกล้เคียงกับกำร ● random เพื่อสร้ำง string
  • 16. message digest ● เครื่องมือบน linux สำำหรับ digest message – md5sum – shasum -a {1,224,256,384,512} ● สร้ำง sum string จำก message ใดๆ ● ถ้ำ message เปลี่ยนไปผล sum จะเปลี่ยนไป
  • 17. ทดลอง ● กำรทดลอง ทั้งหมด ให้ทำำบน VM บน local (notebook) $ echo “a” | md5sum $ echo “hello” | md5sum $ echo “Hello” | md5sum $ echo “How are you doing?” | md5sum $ cat /etc/passwd | md5sum ● เปลียนจำก md5sum เป็ น shasum ­a 1 ่ ● หรือ shasum ­a 224 (เป็ นต้น)
  • 19. เพิ่ม security ● ตัวอักษรที่ได้จำก XXXsum จะมี 'a'-'z','0'-'9' ● ถ้ำมีควำมยำวมำกพอ ก็จะเพิ่ม security ได้ ● แต่เรำสำมำรถสร้ำง output string ที่มีตัวอักษร หลำก หลำยมำกขึ้นได้ โดยกำรใช้ เครื่องมืออื่นเพิ่ม – base64 – uuencode
  • 20. เพิ่ม security (ต่อ) $ echo “a” | shasum ­a 256 | base64 $ echo “a” | shasum ­a 512 | uuencode x $ echo "a" | shasum ­a 256 | base64 ODc0MjhmYzUyMjgwM2QzMTA2NWU3YmNlM2NmMDNmZTQ3N TA5NjYzMWU1ZTA3YmJkN2EwZmRlNjBjNGNmMjVjNyAgLQ o= $ echo "a" | shasum ­a 512 | uuencode x begin 644 x M,38R8C!B,S)F,#(T.#)D­6%C83!A­V,Y,V1D,#­C96%C,V%C9#=E­#$P835F M,3AF,V9B.3DP9F,Y­3AA93!D9C9F,S(R,S­B.3$X,S%E868Y.6­A­3@Q83AC J­&1D9CEC.&)A,S$U86,T.#)D8C9D­&5A,#%C8S<X.#1A­C,U8F4@("T* ` end
  • 21. วิธกำรเอำไปใช้ ี ● เก็บ “string” เริ่มต้น (“a”, “hello”) เป็ นควำมลับ สูงสุด ● เก็บ วิธกำร digest และ encode ทีเลือกใช้เป็ นควำมลับ ี ่ ● เลือกตำำแหน่งเริ่มต้นของ output string ทีเอำมำใช้เป็ นควำมลับ (ไม่ ่ จำำเป็ นจะต้องเริ่มที่ 1) ● แต่ท้ งหมดนั้น จะต้องไม่ลม ั ื ● ถ้ำลืม วิธีกำรทีว่ำมำทั้งหมด ก็ไม่มประโยชน์ ให้กลับไปใช้ ่ ี pwgen -s 16 1 แทนก็จะไม่เสียเวลำ
  • 22. วิธีกำรเอำไปใช้ (ต่อ) ● ถ้ำจำำเป็ น ● แยกจด / แยกเก็บ ● string เริ่มต้น, วิธีกำร sum, วิธีกำร encode จดใส่กระดำษ เก็บร่วมกับ ใบสูตบัตร, เอกสำร ิ สำำคัญอื่นๆ ที่ “หำยไม่ได้” แต่ นำนๆใช้ที
  • 23. วิธีกำรเอำไปใช้ (ต่อ) ● output string สำำหรับ password จดใส่กระดำษ เก็บในกระเป๋ ำสตำงค์ เก็บบัตรประจำำตัวประชำชน หรือ เอกสำรสำำคัญ ชนิดอื่นๆ ทีใช้งำนบ่อย ่ ● pattern ของกำรเลือก password จำก output string ที่เก็บในกระเป๋ ำสตำงค์ จำำ – ใช้งำนบ่อย ไม่จำำเป็ นต้องเปลี่ยนบ่อย จะจำำได้เอง
  • 24. หมำยเหตุ: ● ทุกคำำสั่งที่คุณพิมพ์ บน linux และใช้งำน bash เป็ น shell จะเก็บอยู่ใน .bash_history ● เมื่อ logout ● กำำหนดโดย HISTFILE $ echo $HISTFILE
  • 25. หมำยเหตุ: (cont) ● วิธีกำรไม่ให้บันทึก $ HISTFILE=/dev/null $ exit ● เพื่อให้ string เริ่มต้น, วิธกำร digest, วิธีกำร ี encode เป็ นควำมลับ
  • 26. กำรเปลียน password ่ ● password root และ admin account ใช้ $ sudo passwd root $ sudo passwd admin
  • 27. กำรเปลียน password (cont) ่ ● สำำหรับ mysql admin's password term1:~$ sudo service mysql stop term1:~$ sudo mysqld –skip­grant­tables term2:~$ mysql term2 mysql> update mysql.user        set password=PASSWORD('*************')       where user='root'; term2 mysql> exit; term1:~$ CTRL+''
  • 28. กำรเปลียน password (cont) ่ ● คำำสั่งที่ใช้บน mysql client จะเก็บไว้ใน .mysql_history $ cat .mysql_history $ rm ­f .mysql_history