Open Source How-To

You are here: Home > 1. PSU Open Server > 1.2 PSU12-Fog (ใช้ FogProject) > เตรียม Windows สำหรับ cloning

เตรียม Windows สำหรับ cloning

บันทึกนี้ปรับปรุงล่าสุดเมื่อ 27-05-2565 ดูแลโดย WIBOON

 

  • เตรียม Windows และโปรแกรมควบคุม สำหรับต้นฉบับที่จะใช้ในการ clonning Windows PC ห้องคอม

 

เนื้อหา

1 ติดตั้ง Windows และ Default User Profile

  1.1 วิธีใช้ Windows Enabler

2 Enable User ชื่อ Administrator

3 ติดตั้ง Cygwin

  3.1 ดาวน์โหลดและติดตั้ง Cygwin

  3.2 ดาวน์โหลดและรัน script

  3.3 ตรวจสอบ Cygwin sshd

  3.4 ในกรณี Cygwin มีปัญหา

4 ติดตั้ง WSL (แทน Cygwin)

5 ติดตั้ง Windows Logon/Logoff Script

  5.1 กรณีใช้ Cygwin

    5.1.1 Install scripts

    5.1.2 Reinstall script PSU-ticker

  5.2 กรณีใช้ WSL

6 ติดตั้ง pGina

6.1 ตั้งค่า pGina ให้ใช้ RADIUS server

7 ตั้งค่า wallpaper

  7.1 Wallpaper แบบแก้ไขไม่ได้

  7.2 Wallpaper เปลี่ยนได้

8 การตั้งค่า group policy และ security policy

 

ติดตั้ง Windows และ Default User Profile

 

วิธีใช้ Windows Enabler

  • กดปุ่ม Windows+E เพื่อใช้ download folder ชื่อ Windows Enabler จาก ftp.psu.ac.th/pub/microsoft/Enable_Copy_Profile_Windows7/ จะได้ Folder ที่มี 2 ไฟล์ Windows Enabler.exe และ EnablerDLL.dll ไม่ต้องติดตั้ง ให้รันโปรแกรม Windows Enabler.exe แล้วไปสังเกตที่ Taskbar ให้คลิกที่ไอคอน Windows Enabler เพื่อให้มีคำว่า On
  • คลิกขวา Start > เลือก System > system info > Advanced system settings > แท็บ Advanced > (User Profile) Settings > เลือก user profile ที่ต้องการเช่น john > คลิก CopyTo 2 ครั้ง (สังเกตว่าปุ่มจะเปลี่ยนสีจากเทาเป็นตัวอักษรเข้ม) > ได้ช่องว่างพร้อมปุ่ม Browse

 

Enable User ชื่อ Administrator

ในการติดตั้ง Cygwin หรือ ติดตั้ง WSL จะใช้ user ที่มีสิทธิเทียบเท่า Administrator ก็ได้ ไม่จำเป็นต้อง Enable User

  • login เข้า windows
  • คลิกที่ปุ่ม start พิมพ์ cmd ดูที่ขึ้นมาว่า cmd แล้ว click ขวา แล้วเลือก Run as administrator
  • enable user ชื่อ Administrator พิมพ์ net user administrator <ใส่ password> /active:yes
  • ต้อง restart Windows

 

ติดตั้ง Cygwin

ดาวน์โหลดและติดตั้ง Cygwin

  • login ด้วย user ชื่อ Administrator หรือ
    login ด้วย user ที่มีสิทธิเทียบเท่า Administrator ก็ได้
  • ติดตั้ง Cygwin ให้คลิกขวาที่ Link ข้างล่างนี้และเลือก Save as เพื่อ download ไว้ แต่ไม่ต้องสั่งรัน
    สำหรับ Windows 64 bit https://cygwin.com/setup-x86_64.exe
    สำหรับ Windows 32 bit https://cygwin.com/setup-x86.exe
  • แล้วออกไปที่ Windows CMD แบบ Run as Administrator
    ให้ทำคำสั่ง ณ ตำแหน่งโฟลเดอร์ที่ download ไฟล์ เช่น Downloads ดังนี้
    สำหรับ 64 bit
    cd %HOMEPATH%/Downloads
    setup-x86_64.exe -q -s https://cygwin.mirror.constant.com/ -P openssh,curl,wget,dialog,vim
    หรือ
    setup-x86_64.exe -q -s http://mirrors.psu.ac.th/cygwin -P openssh,curl,wget,dialog,vim
    สำหรับ 32 bit
    cd %HOMEPATH%/Downloads
    setup-x86.exe -q -s https://cygwin.mirror.constant.com/ -P openssh,curl,wget,dialog,vim
    หรือ
    setup-x86.exe -q -s http://mirrors.psu.ac.th/cygwin -P openssh,curl,wget,dialog,vim
  • รอนานสักนิด เมื่อเสร็จจะมีข้อความ Ending cygwin install ให้กด Enter
  • คำสั่งติดตั้งข้างบนนี้ เราสามารถแทนที่ https://cygwin.mirror.constant.com/ ด้วย http://mirrors.psu.ac.th/cygwin ได้

 

ดาวน์โหลดและรัน script

เป็นการตั้งค่าให้ Windows เปิด sshd service

  • เปิดโปรแกรม Cygwin Terminal แบบ Run as Administrator
  • ทำคำสั่ง
    wget -N ftp://ftp.psu.ac.th/pub/psu-installer/cygwin/cygwin-config-sshd.sh
    bash -o igncr cygwin-config-sshd.sh
  • script จะถามยืนยัน ให้กด y และ Enter
    (1)และให้ตั้ง password ของ user ชื่อ cyg_server
    (2)จากนั้นจะ run ไปเรือย ๆ จนเสร็จ
    (3)เมื่อเสร็จจะมีข้อความ cygwin-config-sshd.sh finished และจะออกสู่ prompt

 

ตรวจสอบ Cygwin sshd

เป็นขั้นตอนตรวจสอบ Cygwin ว่าได้ติตดั้งอย่างถูกต้อง มี sshd พร้อมให้บริการให้ทำดังนี้

  • ให้ reboot Windows หลังจากติดตั้ง Cygwin เพื่อให้มีการ start service sshd ขึ้นมาก่อน
  • ให้ login ด้วย user ที่ใช้ติดตั้ง Cygwin
  • เปิดโปรแกรม cygwin terminal หรือ cygwin64 terminal โดยคลิกขวาเลือก Run as Administrator
  • พิมพ์คำส่ง ssh ชื่อuser@127.0.0.1 เช่น user ชื่อ Administrator ก็พิมพ์ว่า
    ssh Administrator@127.0.0.1
    ผลลัพธ์จะต้องมีคำถามให้ตอบ Yes และ ถาม password

 

ในกรณี Cygwin มีปัญหา

ให้ทำดังนี้

  • ให้ login ด้วย user ที่ใช้ติดตั้ง Cygwin
  • เปิดโปรแกรม Cygwin terminal หรือ Cygwin64 terminal โดยคลิกขวาเลือก Run as Administrator
  • รัน script cygwin-uninstall.sh ดังนี้
    bash -o igncr cygwin-uninstall.sh
  • ออก (exit) จาก Cygwin terminal
  • แล้วเข้า Windows Explorer ลบ c:\cygwin หรือ c:\cygwin64 ทิ้ง
  • ย้อนไปทำการติดตั้ง (reinstall) Cygwin ใหม่

 

ติดตั้ง WSL (แทน Cygwin)

 

ติดตั้ง Windows Logon/Logoff Script

เป็นขั้นตอนติดตั้ง script เกี่ยวกับ Windows Computer Name และ เก็บ Windows login record log ด้วย PSU-ticker

 

กรณีใช้ Cygwin

Install scripts

สำหรับ Windows 10 64 bit

  • เปิดโปรแกรม Cygwin(64) Terminal แบบ Run as Administrator
  • Run คำสั่งนี้
    wget -N ftp://ftp.psu.ac.th/pub/psu-installer/cygwin/installchangecomputernametaskwindows1064bit.sh
    bash -o igncr installchangecomputernametaskwindows1064bit.sh
  • ตอนนี้จะเข้าสู่การติดตั้ง script ใน Task Scheduler
    (1)จะ run Task Scheduler ขึ้นมา ให้ click ที่ Task Scheduler Library
    (2)ช่องตรงกลางจะมีคำว่า changecomputernametask ให้ click ขวา เลือก Properties
    (3)ให้เลือก Run whether user is logged on or not และ
    (4)ติ๊กเลือก Run with highest priviledges
    (5)ช่อง Configure for: ให้เลือก Windows10 หรือ รุ่นที่ติดตั้ง แล้ว click OK
    (6)จะมีถาม Password ของ user Administrator (หรือ user ที่ใช้) ให้ใส่ให้ถูกต้อง แล้วคลิก OK
    หมายเหตุ:
    หากใครตั้งค่า task schedule ไม่ผ่านเนื่องจากในขณะใส่รหัสผ่านเพื่อยืนยัน เจอข้อความว่า An error has occurred... user is invalid ให้แก้ไขดังนี้ ในหน้า ตั้ง properties มันมี step ที่เราต้องทำเพิ่มคือ คลิก Change user or group แล้วใส่ชื่อ User แล้วคลิก Check Name จะได้ชื่อเครื่องนำหน้าชื่อ user แล้วคลิก OK แล้วจะทำผ่านได้ (เจอใน Windows 10 รุ่น 1809 ขึ้นไป)
    (7)ถัดไป click ปิด Task Scheduler
    (8)กลับไปที่หน้าต่าง Cygwin จะมีคำถามว่า "Press Enter to continue" ให้กด Enter จากนั้น Windows จะถูก reboot automatic

สำหรับรุ่นอื่น ๆ

  • ดาวน์โหลดจากที่นี่
    ftp://ftp.psu.ac.th/pub/psu-installer/cygwin/
  • ทำขั้นตอนคล้าย ๆ กับตัวอย่างข้างบนนี้

 

Reinstall script PSU-ticker

จากขั้นตอนติดตั้ง script ได้พ่วงเรื่องการจัดการให้แฟ้ม logticker.vbs ทำงานทุกครั้งที่มีการ logon และแฟ้ม stopticker.vbs ทำงานทุกครั้งที่ logoff เพื่อเก็บ log record ให้ด้วยแล้ว หากยังไม่เกิด log record ให้ทำคำสั่งข้างล่างนี้ที่เครื่อง Windows ต้นฉบับ

  • เปิดโปรแกรม Cygwin(64) Terminal แบบ Run as Administrator
  • ทำคำสั่งตามรุ่นที่ใช้
    ตัวอย่างสำหรับ Windows10 64 bit
    bash -o igncr installlogtickerwindows1064bit.sh ชื่อzone เช่น
    bash -o igncr installlogtickerwindows1064bit.sh zone1

 

กรณีใช้ WSL

สำหรับ Windows 10 64 bit

  • เปิด WSL ด้วย Run as Administrator
    cd
    sudo su
    wget -N http://ftp.psu.ac.th/pub/psu-installer/windows/ccntw/installccntw10-wsl.sh
  • Run คำสั่งนี้โดยระบุไอพีแอดเดรสของ DHCPSERVER ด้วย
    bash installccntw10-wsl.sh DHCPSERVER-IP
    กด Enter เพื่อสร้าง task
    ก่อนสร้าง Task จะมีถาม Password ของ user Administrator (หรือ user ที่ใช้) ให้ใส่ให้ถูกต้อง แล้วคลิก OK
    จะสร้าง Task ให้อัตโนมัติแล้ว restart

 

ติดตั้ง pGina

  • ดาวน์โหลดไฟล์ https://github.com/MutonUfoAI/pgina/releases/download/3.9.9.12/pGinaSetup-3.9.9.12.exe มาไว้ใน Windows
  • จากนั้นเลือก Run (pGina จะต้องใช้ชุด Microsoft .NET 4.x และติดตั้งต่อด้วยชุด Microsoft Visual++)

ตั้งค่า pGina ให้ใช้ RADIUS server

  • เปิดโปรแกรม pGina, คลิกแท็บ Plugin Selection ดูที่บรรทัด RADIUS Plugin คลิกเพื่อเลือกที่ช่อง Authentication และ Notification
  • คลิก Configure
    เลือก Enable Authentication เพื่อสอบถาม username/password
    เลือก Enable Accounting เพื่อส่งข้อมูลบันทึกค่า Acct-Status-Type ไปยัง RADIUS Server
    แล้วระบุ Server IP และ Shared Secret ที่จะต้องตรงกันกับที่ระบุอยู่ใน config ที่ RADIUS server เช่น FreeRADIUS 3.x จะอยู่ในไฟล์ /etc/freeradius/3.0/clients.conf เป็นต้น
    เลือก Called-Station-ID ด้วย หากต้องการเลข MAC Address เก็บด้วยนอกจากเก็บ IP
    เลือก Accounting Options หัวข้อ Send Interim Updates เพื่อให้มีการส่งค่า accounting ได้ (โดยใช้ค่า Send update every 900 seconds ตามที่เป็นค่า default)
    ใส่ IP Address Suggestion: ให้ใส่ network id เช่น 192.168.4 สำหรับ net 192.168.4.0/24 เป็นต้น (ใช้สำหรับ Windows ที่มีการลงโปรแกรมประเภท Virtual Machine)
  • แท็บ Plugin Selection ที่บรรทัด Local Machine ติ๊ก Authentication, Gateway และ Notification
  • ดูรูปภาพและเนื้อหาเพิ่มเติม
    https://sysadmin.psu.ac.th/2017/04/12/pgina-fork-3-2-4-1-configuration/
    https://sysadmin.psu.ac.th/2018/09/04/pgina-fork-3-9-9-12-configuration/

 

ตั้งค่า wallpaper

Wallpaper แบบแก้ไขไม่ได้

  • ให้ไปตั้งค่าที่ gpedit.msc ต้องใช้ login ที่เป็นหรือเทียบเท่า Administrator
  • Local Computer Policy\User Configuration\Administrative Templates\Desktop\Desktop\Desktop Wallpaper เลือก Enabled และในช่อง Wallpapaer Name: ใส่ชื่อไฟล์ภาพ

Wallpaper เปลี่ยนได้

  • สร้างโฟลเดอร์ c:\mywallpaper ไว้ เราสามารถส่งรูปภาพ JPG ไปเปลี่ยน desktop เครื่อง Windows ได้
  • ตั้งค่า Background เป็น Slide show แล้วเลือกชี้ไปที่โฟลเดอร์ชื่อ c:\mywallpaper และตั้งค่าเปลี่ยนรูปทุก 1 นาที
  • ต้องมีไฟล์รูปภาพ JPG 2 ไฟล์ (รูปเดียวกันแต่ชื่อไฟล์ต่างกัน) เพื่อให้ Slide show ทำงานได้

 

การตั้งค่า group policy และ security policy

ต้องใช้ login ที่เป็นหรือเทียบเท่า Administrator
ไม่เอา Windows update ให้ไปตั้งค่าที่ gpedit.msc

  • Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\Windows Update\Configure Automatic Updates เลือก Enabled เลือก 2 - Notify for download and notify for install
  • Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\Windows Update\Specify intranet Microsoft update service location เลือก Enabled แล้วใส่ URL ปลอม ๆ เอาไว้


ไม่เอา OneDrive ให้ไปตั้งค่าที่ gpedit.msc

  • Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\OneDrive\Prevent the usage of OneDrive for file storage เลือก Enabled


ไม่ใช้ Fast startup ในคำสั่ง Shutdown ให้ไปตั้งค่าที่ control panel > power options

  • choose what the power button does > change settings that are currently unavailable > uncheck at Turn on fast startup


ไม่แสดงรายชื่อ username ในหน้า login ให้ไปตั้งค่าที่ secpol.msc

  • Security Settings\Local Policies\Security Options\Interactive logon: Don’t display last signed-in เลือก Enable
nach oben