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


    Elastichost
   Server Admin I
    Chatchai J

    2013-01-28
First login
●   ใช้ vncviewer
      $ vncviewer $ELASTICHOSTSIP
       ●   password: *******
       ●   login: root
            –   no password

●   ใช้ secureshell
      $ ssh toor@$ELASTICHOSTSIP
       ●   password: ********
initial setup
●   set root password
      # passwd root
●   disabled 'toor' account
      # passwd ­l toor
●   create admin account
      # useradd ­m ­G sudo ­s /bin/bash ­c “Admin” cj
      # passwd cj
      # apt­get install sudo
initial setup (cont)
●   setup hostname on local VM
        $ sudo sh ­c “echo '216.157.xx.xx remote' >> /etc/hosts”
        $ sudo sh ­c “echo '216.157.83.88 cheshire' >> /etc/hosts”

●   ทดสอบ user ที่สร้างขึ้นโดยการ remote login
        $ ssh user@remote
        $ ssh cj@cheshire
    –   at remote vm
        $ sudo apt­get ­y update
●   ถ้าใช้งานได้แสดงว่า setup ถูกต้อง
Setup secure shell key
●   เพื่อให้การส่งคำาสั่งไปยัง remote server ทำาได้สะดวก
    มากขึ้น และ ไม่จำาเป็ นต้องใช้ GUI (vncviewer)

●   local – Linux VM ใช้ local:~$

●   remote – Elastichost VM ใช้ remote:~$
    local:~$ 
    remote:~$
Setup secure shell key (cont)
●   สร้าง secure shell key สำาหรับ remote login โดยไม่ต้องใช้
    pass-phrase หรือ password
    local:~$ ssh­keygen
    Enter file in which to save the key (/home/cj/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 

●   ให้ เคาะ ENTER ผ่านทั้งคำาถาม สำาหรับชื่อไฟล์ และ
    passphrase ทั้งสองครั้ง

●   จะได้ไฟล์ id_rsa และ id_rsa.pub ใน sub directory .ssh
Setup secure shell key (cont)
●   ส่ง key ไปเก็บไว้ที่ remote host
    local:~$ ssh­copy­id user@remote
    user@remote's password:

●   มี message เตือนให้ตรวจสอบไฟล์ ~/.ssh/authorized_keys บน
    remote host
●   มันคือไฟล์เดียวกันกับ ~/.ssh/id_rsa.pub

●   ลองเปรียบเทียบโดยการใช้คำาสั่ง
      local:~$ ssh user@remote cat .ssh/authorized_keys
      local:~$ cat .ssh/id_rsa.pub
Setup secure shell key (cont)
●   ข้อสังเกต: ตอนนี้เราสามารถ login ไปที่ remote
    host และ execute คำาสั่งได้แล้ว โดยไม่ต้องป้ อน
    password ใดๆ

●   ใช้ความสามารถของ secure shell และใช้ private
    key ~/.ssh/id_rsa
●   ซึ่ง สะดวก แต่ อันตราย
Setup secure shell key (cont)
●   สะดวก แต่ อันตราย

●   ใครก็ตาม ซึ่งมีไฟล์ id_rsa ของเรา สามารถใช้สิทธิของเรา ใน
    การทำางานใดๆ บนเครื่อง remote host ได้ โดยไม่จำาเป็ นจะ
    ต้องรู้ password

●   โดยเฉพาะถ้า กำาหนด sudo บางคำาสั่งแบบ NOPASSWD:

●   วิธีการป้ องกัน: เพิ่ม passphrase ให้กับ key ของเรา
      local:~$ ssh­keygen ­p
Setup secure shell key (cont)
●   ปั ญหา:

    –   ทุกครั้งที่เรียกใช้คำาสั่งจะต้องป้ อน passphrase
        ●   WRONG – ถ้าใช้ gnome windows manager

        ●   จริงเฉพาะใช้ text mode

    –   เหมือนกับตอนที่ไม่ได้ setup key
        ●   เปลียนจาก password มาใช้ passphrase
                ่

●   secure shell key ไม่ได้ช่วยอะไร?
Setup secure shell key (cont)
●   ถ้าอยู่ใน GUI ให้ logout และ login ใหม่

●   Gnome จะมี gnome-keyring-daemon และ seahorse Encryption
    Key Manager คอยจัดการ key ให้
●   Menu “System” ->”Preferences”->”Passwords and Encryption Keys”
●   เลือก Tab “Personal Keys”

●   สามารถ Export, Copy, Delete, Change Comment/Password ได้
keychain
●   ถ้าใช้ terminal console และ remote login หรือ เครื่องที่
    ใช้ในการจัดการ ไม่ได้ run gnome โดยตรง
●   Notebook →Admin PC → Server
●   GUI (gnome) → text terminal → text terminal
●   สามารถใช้ keychain สำาหรับทำางานแบบเดียวกันกับ
    Seahorse
keychain (cont)
●   ติดตั้ง keychain
      local:~$ sudo apt­get install keychain ssh­askpass

●   เพิ่มลงไปใน .bashrc
     if [ ­x /usr/bin/keychain ]; then
             keychain id_rsa
             [ ­z "$HOSTNAME" ] && HOSTNAME=`uname ­n`
             [ ­f $HOME/.keychain/$HOSTNAME­sh ] && 
                     . $HOME/.keychain/$HOSTNAME­sh
     fi
Setup secure shell key (cont)
●   หลังจากใช้งาน keychain หรือ seahorse ก็จะทำาให้
    สามารถ ป้ อน passphrase เพียงครั้งเดียว ก็จะใช้
    secure shell key ในครั้งต่อๆไปได้

●   การใช้ secure shell key ยังมีความสามารถอื่นๆ อีก
    มาก เช่น ระบุว่าใช้ key นี้ run เฉพาะคำาสั่งนี้ โดย
    ส่งมาจาก host นี้เท่านั้น
sync config using rsync
●   เพื่อความสะดวกในการแก้ไข / backup config

    –   sync config จาก remote → local

    –   ใช้ rsync

    –   จะต้องมี rsync ทั้งที่ local และ remote
        local:~$ sudo apt­get install rsync
        local:~$ ssh ­t remote sudo apt­get install rsync
sync config (cont)
●   First Sync
    local:~$ sudo su
    local:~# cd; mkdir REMOTE; cd REMOTE
    local:~/REMOTE# rsync ­avuP root@remote:/etc/ etc

    lsa:~$ sudo su
    lsa:~# cd; mkdir cheshire; cd cheshire
    lsa:~/cheshire# rsync ­avuP root@cheshire:/etc/ etc
sync config (cont)
●   แก้ไขข้อมูล

●   sync กลับ

    local:~/REMOTE# rsync ­avuP etc root@remote:/

    lsa:~/cheshire# rsync ­avuP etc root@cheshire:/


●   จะมีเฉพาะไฟล์ที่ถูกแก้ไขเท่านั้น ที่ถูกส่งกลับไป
sync config (for bind)
local:~/REMOTE# rsync ­avuP root@remote:/var/cache/bind bind

local:~/REMOTE# rsync ­avuP bind root@remote:/var/cache/
sync config (deleted files)
●   rsync --delete --delete-after
●   อ่าน manual page ของ rsync สำาหรับ option
    อื่นๆ

●   เป็ นเครื่องมือที่มีประโยชน์มาก
sync config
●   Note:
    –   ทุกครั้ง ก่อนที่จะแก้ไข config ที่ local copy

    –   ให้ sync config จาก remote server มาก่อนเสมอ

    –   แก้ไขแล้ว ค่อย sync กลับไป
●   YOU HAVE BEEN WARNED
●   การติดตั้ง/update package จะมีการแก้ไข config ที่ตัว server เพราะ
    ฉะนั้น ให้ถือว่า ข้อมูลที่ server มีความทันสมัยกว่า เสมอ

●   ยกเว้นกรณีที่ ทำาผิดพลาดบน server (เช่น ลบไฟล์ผิด)
Elastic VM Setup
●   /etc/hostname
    –   cheshire.cheshirecat2012.net
    –   ใช้ช่ อเฉพาะ (cheshire) ไม่ควรใช้ช่ อ ฟั งก์ชน/หน้าที่ (www, ns, smtp,
              ื                             ื        ั
        …)
    –   หน้าที่สามารถย้ายไปอยู่ server ตัวอื่นได้ เมื่อเรามี server ให้ใช้มาก
        ขึ้น
●   /etc/apt/sources.list
    –   default point to ftp.uk.debian.org
    –   elastichosts อยู่ใน US => ftp.us.debian.org
VM Setup (cont)
●   ติดตั้ง pacakge ที่ต้องการใช้งานบน server
    local:~$ ssh ­t remote sudo apt­get install tmux

●   เป็ นต้น
Ch15 elastic hosts-svradmin

More Related Content

What's hot (8)

Ch06 bind9
Ch06 bind9Ch06 bind9
Ch06 bind9
 
Docker 101 for developer
Docker 101 for developerDocker 101 for developer
Docker 101 for developer
 
Ch08 mail-systems
Ch08 mail-systemsCh08 mail-systems
Ch08 mail-systems
 
VBoxManage tutorial
VBoxManage tutorialVBoxManage tutorial
VBoxManage tutorial
 
Server2Go เว็บพกพาตัวจริง
Server2Go เว็บพกพาตัวจริงServer2Go เว็บพกพาตัวจริง
Server2Go เว็บพกพาตัวจริง
 
Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )Android Control Hardware and Arduino IoT ( 22 Aug 15 )
Android Control Hardware and Arduino IoT ( 22 Aug 15 )
 
Ch07 bind9-part2
Ch07 bind9-part2Ch07 bind9-part2
Ch07 bind9-part2
 
Editors for-linux
Editors for-linuxEditors for-linux
Editors for-linux
 

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 (13)

CompTIA Linux+
CompTIA Linux+CompTIA Linux+
CompTIA Linux+
 
Ch10 web servers
Ch10 web serversCh10 web servers
Ch10 web servers
 
Ch17 secure-password
Ch17 secure-passwordCh17 secure-password
Ch17 secure-password
 
Ch01 administrators-tasks
Ch01 administrators-tasksCh01 administrators-tasks
Ch01 administrators-tasks
 
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
 

Similar to Ch15 elastic hosts-svradmin (12)

Linux diskless
Linux disklessLinux diskless
Linux diskless
 
NETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUIDNETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUID
 
Ch02 administrators-tasks
Ch02 administrators-tasksCh02 administrators-tasks
Ch02 administrators-tasks
 
คู่มือการติดตั้ง Cent os
คู่มือการติดตั้ง  Cent osคู่มือการติดตั้ง  Cent os
คู่มือการติดตั้ง Cent os
 
Cent os
Cent osCent os
Cent os
 
Basic linux
Basic linuxBasic linux
Basic linux
 
Basic Linux
Basic LinuxBasic Linux
Basic Linux
 
Docker 1st time
Docker 1st timeDocker 1st time
Docker 1st time
 
Bug#691613: apt: [intl:th] update thai program translation
Bug#691613: apt: [intl:th] update thai program translationBug#691613: apt: [intl:th] update thai program translation
Bug#691613: apt: [intl:th] update thai program translation
 
Multi threaded programming in c and c++ 2021-09-03
Multi threaded programming in c and c++ 2021-09-03Multi threaded programming in c and c++ 2021-09-03
Multi threaded programming in c and c++ 2021-09-03
 
Red5 workshop
Red5 workshopRed5 workshop
Red5 workshop
 
Portable Moodle : Moodle & Server2Go
Portable Moodle  : Moodle & Server2GoPortable Moodle  : Moodle & Server2Go
Portable Moodle : Moodle & Server2Go
 

Ch15 elastic hosts-svradmin

  • 1. Linux Server Admin Elastichost Server Admin I Chatchai J 2013-01-28
  • 2. First login ● ใช้ vncviewer $ vncviewer $ELASTICHOSTSIP ● password: ******* ● login: root – no password ● ใช้ secureshell $ ssh toor@$ELASTICHOSTSIP ● password: ********
  • 3. initial setup ● set root password # passwd root ● disabled 'toor' account # passwd ­l toor ● create admin account # useradd ­m ­G sudo ­s /bin/bash ­c “Admin” cj # passwd cj # apt­get install sudo
  • 4. initial setup (cont) ● setup hostname on local VM $ sudo sh ­c “echo '216.157.xx.xx remote' >> /etc/hosts” $ sudo sh ­c “echo '216.157.83.88 cheshire' >> /etc/hosts” ● ทดสอบ user ที่สร้างขึ้นโดยการ remote login $ ssh user@remote $ ssh cj@cheshire – at remote vm $ sudo apt­get ­y update ● ถ้าใช้งานได้แสดงว่า setup ถูกต้อง
  • 5. Setup secure shell key ● เพื่อให้การส่งคำาสั่งไปยัง remote server ทำาได้สะดวก มากขึ้น และ ไม่จำาเป็ นต้องใช้ GUI (vncviewer) ● local – Linux VM ใช้ local:~$ ● remote – Elastichost VM ใช้ remote:~$ local:~$  remote:~$
  • 6. Setup secure shell key (cont) ● สร้าง secure shell key สำาหรับ remote login โดยไม่ต้องใช้ pass-phrase หรือ password local:~$ ssh­keygen Enter file in which to save the key (/home/cj/.ssh/id_rsa):  Enter passphrase (empty for no passphrase):  Enter same passphrase again:  ● ให้ เคาะ ENTER ผ่านทั้งคำาถาม สำาหรับชื่อไฟล์ และ passphrase ทั้งสองครั้ง ● จะได้ไฟล์ id_rsa และ id_rsa.pub ใน sub directory .ssh
  • 7. Setup secure shell key (cont) ● ส่ง key ไปเก็บไว้ที่ remote host local:~$ ssh­copy­id user@remote user@remote's password: ● มี message เตือนให้ตรวจสอบไฟล์ ~/.ssh/authorized_keys บน remote host ● มันคือไฟล์เดียวกันกับ ~/.ssh/id_rsa.pub ● ลองเปรียบเทียบโดยการใช้คำาสั่ง local:~$ ssh user@remote cat .ssh/authorized_keys local:~$ cat .ssh/id_rsa.pub
  • 8. Setup secure shell key (cont) ● ข้อสังเกต: ตอนนี้เราสามารถ login ไปที่ remote host และ execute คำาสั่งได้แล้ว โดยไม่ต้องป้ อน password ใดๆ ● ใช้ความสามารถของ secure shell และใช้ private key ~/.ssh/id_rsa ● ซึ่ง สะดวก แต่ อันตราย
  • 9. Setup secure shell key (cont) ● สะดวก แต่ อันตราย ● ใครก็ตาม ซึ่งมีไฟล์ id_rsa ของเรา สามารถใช้สิทธิของเรา ใน การทำางานใดๆ บนเครื่อง remote host ได้ โดยไม่จำาเป็ นจะ ต้องรู้ password ● โดยเฉพาะถ้า กำาหนด sudo บางคำาสั่งแบบ NOPASSWD: ● วิธีการป้ องกัน: เพิ่ม passphrase ให้กับ key ของเรา local:~$ ssh­keygen ­p
  • 10. Setup secure shell key (cont) ● ปั ญหา: – ทุกครั้งที่เรียกใช้คำาสั่งจะต้องป้ อน passphrase ● WRONG – ถ้าใช้ gnome windows manager ● จริงเฉพาะใช้ text mode – เหมือนกับตอนที่ไม่ได้ setup key ● เปลียนจาก password มาใช้ passphrase ่ ● secure shell key ไม่ได้ช่วยอะไร?
  • 11. Setup secure shell key (cont) ● ถ้าอยู่ใน GUI ให้ logout และ login ใหม่ ● Gnome จะมี gnome-keyring-daemon และ seahorse Encryption Key Manager คอยจัดการ key ให้ ● Menu “System” ->”Preferences”->”Passwords and Encryption Keys” ● เลือก Tab “Personal Keys” ● สามารถ Export, Copy, Delete, Change Comment/Password ได้
  • 12. keychain ● ถ้าใช้ terminal console และ remote login หรือ เครื่องที่ ใช้ในการจัดการ ไม่ได้ run gnome โดยตรง ● Notebook →Admin PC → Server ● GUI (gnome) → text terminal → text terminal ● สามารถใช้ keychain สำาหรับทำางานแบบเดียวกันกับ Seahorse
  • 13. keychain (cont) ● ติดตั้ง keychain local:~$ sudo apt­get install keychain ssh­askpass ● เพิ่มลงไปใน .bashrc if [ ­x /usr/bin/keychain ]; then         keychain id_rsa         [ ­z "$HOSTNAME" ] && HOSTNAME=`uname ­n`         [ ­f $HOME/.keychain/$HOSTNAME­sh ] &&                  . $HOME/.keychain/$HOSTNAME­sh fi
  • 14. Setup secure shell key (cont) ● หลังจากใช้งาน keychain หรือ seahorse ก็จะทำาให้ สามารถ ป้ อน passphrase เพียงครั้งเดียว ก็จะใช้ secure shell key ในครั้งต่อๆไปได้ ● การใช้ secure shell key ยังมีความสามารถอื่นๆ อีก มาก เช่น ระบุว่าใช้ key นี้ run เฉพาะคำาสั่งนี้ โดย ส่งมาจาก host นี้เท่านั้น
  • 15. sync config using rsync ● เพื่อความสะดวกในการแก้ไข / backup config – sync config จาก remote → local – ใช้ rsync – จะต้องมี rsync ทั้งที่ local และ remote local:~$ sudo apt­get install rsync local:~$ ssh ­t remote sudo apt­get install rsync
  • 16. sync config (cont) ● First Sync local:~$ sudo su local:~# cd; mkdir REMOTE; cd REMOTE local:~/REMOTE# rsync ­avuP root@remote:/etc/ etc lsa:~$ sudo su lsa:~# cd; mkdir cheshire; cd cheshire lsa:~/cheshire# rsync ­avuP root@cheshire:/etc/ etc
  • 17. sync config (cont) ● แก้ไขข้อมูล ● sync กลับ local:~/REMOTE# rsync ­avuP etc root@remote:/ lsa:~/cheshire# rsync ­avuP etc root@cheshire:/ ● จะมีเฉพาะไฟล์ที่ถูกแก้ไขเท่านั้น ที่ถูกส่งกลับไป
  • 18. sync config (for bind) local:~/REMOTE# rsync ­avuP root@remote:/var/cache/bind bind local:~/REMOTE# rsync ­avuP bind root@remote:/var/cache/
  • 19. sync config (deleted files) ● rsync --delete --delete-after ● อ่าน manual page ของ rsync สำาหรับ option อื่นๆ ● เป็ นเครื่องมือที่มีประโยชน์มาก
  • 20. sync config ● Note: – ทุกครั้ง ก่อนที่จะแก้ไข config ที่ local copy – ให้ sync config จาก remote server มาก่อนเสมอ – แก้ไขแล้ว ค่อย sync กลับไป ● YOU HAVE BEEN WARNED ● การติดตั้ง/update package จะมีการแก้ไข config ที่ตัว server เพราะ ฉะนั้น ให้ถือว่า ข้อมูลที่ server มีความทันสมัยกว่า เสมอ ● ยกเว้นกรณีที่ ทำาผิดพลาดบน server (เช่น ลบไฟล์ผิด)
  • 21. Elastic VM Setup ● /etc/hostname – cheshire.cheshirecat2012.net – ใช้ช่ อเฉพาะ (cheshire) ไม่ควรใช้ช่ อ ฟั งก์ชน/หน้าที่ (www, ns, smtp, ื ื ั …) – หน้าที่สามารถย้ายไปอยู่ server ตัวอื่นได้ เมื่อเรามี server ให้ใช้มาก ขึ้น ● /etc/apt/sources.list – default point to ftp.uk.debian.org – elastichosts อยู่ใน US => ftp.us.debian.org
  • 22. VM Setup (cont) ● ติดตั้ง pacakge ที่ต้องการใช้งานบน server local:~$ ssh ­t remote sudo apt­get install tmux ● เป็ นต้น