SiamGURU
pdfหน้าเว็บ

aaaaaa

สำนักงานพัฒนารัฐบาลดิจิทัล

ไฟล์ต้นฉบับ

เนื้อหา

หน้า 1

การใช้งาน CentOS 7 เบื้องต้น คมกริช ค าสวัสดิ์ วิศวกรอาวุโส ส านักงานรัฐบาลอิเล็กทรอนิกส์ ( องค์การมหาชน ) 1

หน้า 2

การใช้งาน CentOS 7 เบื้องต้น - Installation - Sync system time with NTP server - Install additional packages - Update/Upgrade - Local Firewall by iptables - SSH basic Hardening - Send system log to Syslog server - NTP service - MariaDB - MySQL - Web server (HTTPD) - FTP server (VSFTPD) 2

หน้า 3

www.centos.org 3

หน้า 4

www.centos.org 4

หน้า 5

การติดตั้ง CentOS 7 5

หน้า 6

การติดตั้ง CentOS 7 : Boot from CD 6

หน้า 7

การติดตั้ง CentOS 7 : เลือกภาษา 7

หน้า 8

การติดตั้ง CentOS 7 : ส่วนก าหนดค่าพื้นฐานของระบบ 8

หน้า 9

การติดตั้ง CentOS 7 : Time Zone 9

หน้า 10

การติดตั้ง CentOS 7 : Network 10

หน้า 11

การติดตั้ง CentOS 7 : Network 11

หน้า 12

การติดตั้ง CentOS 7 : Network 12

หน้า 13

การติดตั้ง CentOS 7 : Network 13

หน้า 14

การติดตั้ง CentOS 7 : Network

หน้า 15

การติดตั้ง CentOS 7 : Disk Partition (Auto partition)

หน้า 16

การติดตั้ง CentOS 7 : Disk Partition (Auto partition)

หน้า 17

การติดตั้ง CentOS 7 : Disk Partition (Auto partition)

หน้า 18

การติดตั้ง CentOS 7 : Disk Partition (Auto partition)

หน้า 19

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 20

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 21

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 22

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 23

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 24

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 25

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 26

การติดตั้ง CentOS 7 : Disk Partition (Manual partition)

หน้า 27

การติดตั้ง CentOS 7 : Disk Partition

หน้า 28

การติดตั้ง CentOS 7

หน้า 29

การติดตั้ง CentOS 7 : Username/Password

หน้า 30

การติดตั้ง CentOS 7 : Username/Password

หน้า 31

การติดตั้ง CentOS 7 : Username/Password Weak Password Warning!

หน้า 32

การติดตั้ง CentOS 7 : Username/Password Weak Password Warning!

หน้า 33

การติดตั้ง CentOS 7 : Username/Password

หน้า 34

การติดตั้ง CentOS 7 : Username/Password

หน้า 35

การติดตั้ง CentOS 7 : Username/Password

หน้า 36

การติดตั้ง CentOS 7

หน้า 37

การติดตั้ง CentOS 7

หน้า 38

การติดตั้ง CentOS 7 : พร้อมใช้งาน

หน้า 39

ข้อยกเว้นส าหรับเอกสารนี้ !!!!!!!! 39 เพื่อให้ง่ายในการทดสอบปฏิบัติใน Class นี้ จึงขอให้ท าการ Disable SELINUX ดังนี้ - ท าการแก้ไขไฟล์ / etc / selinux / config ดังนี้ SELINUX=disabled - ท าการแก้ไขโหมดการท างานของ SELINUX เป็น Permissive [ root@server 1 ~]# setenforce 0 - ตรวจสอบการท างานของ SELINUX [root@server 1 ~]# getenforce Permissive

หน้า 40

การเทียบเวลาเครื่องกับ Time server 40 [root@server 1 ~]# yum - y install ntpdate [root@server 1 ~]# ntpdate time.navy.mi.th 26 Jul 11:29:06 ntpdate [ 2399 ]: step time server 113.53.247.3 offset - 28788.342002 sec [root@server 1 ~]# date Tue Jul 26 11:29:16 ICT 2016

หน้า 41

แนะน าให้ติดตั้งเพิ่ม !!! 41 [root@server 1 ~]# yum - y install wget net - tools epel - release หมายเหตุ wget ใช้ส าหรับ Download ไฟล์จาก Network net - tools เป็นชุดค าสั่งเกี่ยวกับการจัดการเครือ ช่าย เช่น ifconfig , netstat เป็นต้น e pel - release เป็น repo ส าหรับการติดตั้ง Sofware package บางตัว

หน้า 42

การ Update/Upgrade ระบบ 42 [root@server 1 ~]# yum - y upgrade Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror 1 .ku.ac.th * extras: mirror 1 .ku.ac.th * updates: mirror 1 .ku.ac.th Resolving Dependencies ......... . ......... . ......... . Complete! [root@server 1 ~]# reboot

หน้า 43

Local Firewall by iptables ติดตั้ง iptables - services [root@server 1 ~]# yum - y install iptables - service ก าหนดให้ iptables ท างานทุกครั้งเมื่อมีการ reboot เครื่อง [root@server 1 ~]# systemctl enable iptables เปิดการท างานของ iptables [root@server 1 ~]# systemctl start iptables 43

หน้า 44

iptables ตรวจสอบการท างานของ iptables root@server 1 ~]# iptables - nvL 44

หน้า 45

iptables แก้ไข Rules ของ iptables โดยการแก้ที่ไฟล์ / etc / sysconfig / iptables * filter : INPUT ACCEPT [ 0:0 ] : FORWARD ACCEPT [ 0:0 ] : OUTPUT ACCEPT [ 0:0 ] - A INPUT - m state -- state RELATED,ESTABLISHED - j ACCEPT - A INPUT - p icmp - j ACCEPT - A INPUT - i lo - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 22 - j ACCEPT - A INPUT - j REJECT -- reject - with icmp - host - prohibited - A FORWARD - j REJECT -- reject - with icmp - host - prohibited COMMIT 45

หน้า 46

iptables ตัวอย่างการเพิ่ม Rules ของ iptables - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 22 - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 80 - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 443 - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 3306 - j ACCEPT เมื่อแก้ไขเสร็จแล้ว ท าการ restart iptables [root@server 1 ~]# systemctl restart iptables 46

หน้า 47

iptables ตรวจสอบการท างานของ iptables หมายเหตุ ส าหรับ IPv 6 ให้เปลี่ยน command จาก iptables เป็น ip 6 tables 47

หน้า 48

SSH basic Hardening - Disable Root Login แก้ไขไฟล์ / etc / ssh / sshd_config จากเดิม # PermitRootLogin yes แก้เป็น PermitRootLogin no แล้วท าการ restart SSH service [root@server 1 ~]# systemctl restart sshd 48

หน้า 49

SSH basic Hardening - อนุญาตเฉพาะบาง Users หรือ บาง Groups เท่านั้นที่สามารถ Login ได้ แก้ไขไฟล์ / etc / ssh / sshd_config โดยเพิ่ม Configuration ต่อไปนี้ กรณีอนุญาต Users AllowUsers user 1 user 2 user 3 กรณีอนุญาต Groups AllowGroups group 1 group 2 group 3 แล้วท าการ restart SSH service [root@server 1 ~]# systemctl restart sshd 49

หน้า 50

SSH basic Hardening - ไม่อนุญาตเฉพาะบาง User s หรือ บาง Groups ให้สามารถ Login ได้ แก้ไขไฟล์ / etc / ssh / sshd_config โดยเพิ่ม Configuration ต่อไปนี้ กรณีไม่อนุญาต Users DenyUsers user 1 user 2 user 3 กรณีไม่อนุญาต Groups DenyGroups group 1 group 2 group 3 แล้วท าการ restart SSH service [root@server 1 ~]# systemctl restart sshd 50

หน้า 51

SSH basic Hardening ตัวอย่าง Log ของ SSH (/ var /log/secure) Aug 7 17:20:22 server 1 sshd [ 4284 ]: User webadmin from 192.168.146.1 not allowed because none of user's groups are listed in AllowGroups Aug 7 17:23:47 server 1 sshd [ 4304 ]: User webadmin from 192.168.146.1 not allowed because a group is listed in DenyGroups Aug 7 17:25:31 server 1 sshd [ 4307 ]: Failed password for root from 192.168.146.1 port 62404 ssh 2 Aug 7 17:26:32 server 1 sshd [ 4320 ]: Accepted password for webadmin from 192.168.146.1 port 62412 ssh 2 Aug 7 17:26:32 server 1 sshd [ 4320 ]: pam_unix ( sshd:session ): session opened for user webadmin by ( uid = 0 ) Aug 7 17:26:34 server 1 sshd [ 4320 ]: pam_unix ( sshd:session ): session closed for user webadmin 51

หน้า 52

การส่ง System Log ไปเก็บที่ Syslog server แก้ไขไฟล์ / etc / rsyslog.conf กรณีส่งแบบ UDP *.* @Log - Server.or.IP กรณีส่งเป็น TCP *.* @@Log - Server.or.IP จากนั้นท าการ restart syslog service [root@server 1 ~]# systemctl restart rsyslog 52

หน้า 53

การติดตั้ง NTP service 53 [root@server 1 ~]# yum - y install ntp [root@server 1 ~]# systemctl enable ntpd Created symlink from / etc / systemd /system/multi - user.target.wants / ntpd.service to / usr /lib/ systemd /system/ ntpd.service . [root@server 1 ~]# systemctl start ntpd ● ntpd.service - Network Time Service Loaded: loaded (/ usr /lib/ systemd /system/ ntpd.service ; enabled; vendor preset: disabled) Active: active (running) since Wed 2016 - 07 - 27 21:45:35 ICT; 7 h left Main PID: 2496 ( ntpd ) CGroup : / system.slice / ntpd.service └─ 2496 / usr / sbin / ntpd - u ntp:ntp - g

หน้า 54

การติดตั้ง NTP service 54 - แก้ไข Time server โดยการแก้ไขไฟล์ / etc / ntp.conf server time.ega.or.th iburst s erver time.navy.mi.th iburst server time 1 .nimt.or.th iburst server time 2 .nimt.or.th iburst จากนั้นท าการ restart service [root@server 1 ~]# systemctl restart ntpd

หน้า 55

การติดตั้ง NTP service 55 ท าการตรวจสอบการท างานผ่าน ntpq [root@server 1 ~]# ntpq - pn remote refid st t when poll reach delay offset jitter ============================================================================== * 164.115.18.123 .PPS. 1 u 15 64 1 1.553 28.889 17.840 113.53.247.3 .PPS. 1 u 26 64 0 0.000 0.000 0.000 203.185.69.60 .IRIG. 1 u 26 64 0 0.000 0.000 0.000 203.185.69.59 .GPS. 1 u 26 64 0 0.000 0.000 0.000 [root@server 1 ~]# timedatectl Local time: Wed 2016 - 07 - 27 13:56:20 ICT Universal time: Wed 2016 - 07 - 27 06:56:20 UTC RTC time: Wed 2016 - 07 - 27 06:56:19 Time zone: Asia/Bangkok (ICT, + 0700 ) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a

หน้า 56

MariaDB 56 https://mariadb.org/about/

หน้า 57

MariaDB ติดตั้ง MariaDB server [ root@server 1 ~]# yum - y install mariadb - server ก าหนดให้ MariaDB ท างานทุกครั้งเมื่อมีการ reboot เครื่อง [root@server 1 ~]# systemctl enable mariadb สั่งให้ MariaDB service ท างาน [root@server 1 ~]# systemctl start mariadb 57

หน้า 58

MariaDB ตรวจสอบสถานะของ MariaDB service [ root@server 1 ~]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/ usr /lib/ systemd /system/ mariadb.service ; enabled ; vendor preset: disabled) Active: active (running) since Sat 2016 - 08 - 06 18:15:59 ICT; 23 s ago Process: 10138 ExecStartPost =/ usr / libexec / mariadb - wait - ready $MAINPID (code=exited, status= 0 /SUCCESS) Process: 10058 ExecStartPre =/ usr / libexec / mariadb - prepare - db - dir %n (code=exited, status= 0 /SUCCESS) Main PID: 10137 ( mysqld_safe ) CGroup : / system.slice / mariadb.service ├─ 10137 /bin/ sh / usr /bin/ mysqld_safe -- basedir =/ usr └─ 10295 / usr / libexec / mysqld -- basedir =/ usr -- datadir =/ var /lib/ mysql -- plugin - dir =/ usr /lib 64 / mysql /plugin -- log - error=/ var /log/ mariadb /mariadb.log -- pid - file=/ var /r... 58

หน้า 59

MariaDB ตรวจสอบสถานะของ MariaDB service [root@server 1 ~]# netstat - antp Active Internet connections (servers and established) Proto Recv - Q Send - Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0 :* LISTEN 10295 / mysqld 59

หน้า 60

MariaDB : mysql_secure_installation การก าหนด Password ให้ Root ของ MariaDB [root@server 1 ~]# mysql_secure_installation ... Enter current password for root (enter for none ): <ENTER> OK, successfully used password, moving on... 60

หน้า 61

MariaDB : mysql_secure_installation Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation . Set root password? [Y/n ] <ENTER> New password : <New Password> Re - enter new password : <New Password> Password updated successfully! Reloading privilege tables.. ... Success! 61

หน้า 62

MariaDB : mysql_secure_installation By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n ] <ENTER> ... Success! 62

หน้า 63

MariaDB : mysql_secure_installation Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n ] <ENTER> ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n ] <ENTER> - Dropping test database... ... Success! - Removing privileges on test database... ... Success! 63

หน้า 64

MariaDB : mysql_secure_installation Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n ] <ENTER> ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB ! 64

หน้า 65

MariaDB ทดสอบการเข้าใช้งาน MariaDB [root@server 1 ~]# mysql - u root - p 65

หน้า 66

MariaDB การก าหนดให้ MariaDB สามารถเข้าใช้งานได้จาก Localhost เท่านั้น ( ซึ่งเหมาะสมในกรณีที่ Application และ Database อยู่บนเครื่องเดียวกัน ) โดยให้ท าการแก้ไขไฟล์ชื่อ / etc / my.cnf แล้วใส่ค่า Configuration ดังนี้ [ mysqld ] bind - address= 127.0.0.1 จากนั้นท าการ restart mariadb [root@server 1 ~]# systemctl restart mariadb 66

หน้า 67

MariaDB ตรวจสอบสถานะของ MariaDB service [root@server 1 ~]# netstat - antp Active Internet connections (servers and established) Proto Recv - Q Send - Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0 :* LISTEN 10649 / mysqld 67

หน้า 68

MariaDB การเปลี่ยน User Root ของ Database Login เข้า MariaDB โดย root [root@server 1 etc]# mysql - u root - p Enter password : <password> ท าการแก้ไข Username ด้วยค าสั่ง MariaDB [(none)]> use mysql ; MariaDB [ mysql ]> update user set user =" zeus " where user ="root "; MariaDB [ mysql ]> flush privileges; 68

หน้า 69

MariaDB การเปลี่ยน User Root ของ Database - ก่อนเปลี่ยน - หลังเปลี่ยน 69

หน้า 70

MariaDB การเปลี่ยน User Root ของ Database 70

หน้า 71

MariaDB ลบ MySQL History file โดยปกติ MariaDB หรือ MySQL จะเก็บประวัติการใช้ค าสั่ง SQL ไว้ที่ ~/. mysql_history เช่น /root/. mysql_history หรือที่ /home /<username >/. mysql_history การแก้ไขสามารถท าได้โดยลบไฟล์นั้นทิ้งได้โดยตรง และสร้าง Shortcut ไปที่ /dev/null เพื่อ ป้องกันการเขียนประวัติในอนาคต ดังนี้ [ root@server 1 ~]# ls - la / root/. mysql_history - rw ------- 1 root root 662 Aug 6 23:46 /root/. mysql_history [ root@server 1 ~]# rm /root/. mysql_history rm : remove regular file ‘ /root/. mysql_history ’ ? y 71

หน้า 72

MariaDB ลบ MySQL History file ท าการสร้าง Sh o rtcut ไปยัง /dev/null [root@server 1 ~]# ln - s / dev/null /root/. mysql_history ตรวจสอบโดย [root@server 1 ~]# ls - la /root/. mysql_history lrwxrwxrwx 1 root root 9 Aug 6 23:55 /root/. mysql_history - > /dev/null 72

หน้า 73

MySQL 73

หน้า 74

MySQL 74

หน้า 75

MySQL 75

หน้า 76

MySQL การติดตั้ง MySQL server [root@server 1 ~]# rpm - ivh https :// dev.mysql.com/get/mysql 57 - community - release - el 7 - 8 .noarch.rpm warning: / var / tmp /rpm - tmp.XPAw 1 n: Header V 3 DSA/SHA 1 Signature, key ID 5072 e 1 f 5 : NOKEY Preparing... ################################# [ 100 %] Updating / installing... 1 :mysql 57 - community - release - el 7 - 8 ################################# [ 100 %] 76

หน้า 77

MySQL ติดตั้ง MySQL server [ root@server 1 ~]# yum - y install mysql - server ก าหนดให้ MySQL ท างานทุกครั้งเมื่อมีการ reboot เครื่อง [root@server 1 ~]# systemctl enable mysqld สั่งให้ MySQL service ท างาน [root@server 1 ~]# systemctl start mysqld 77

หน้า 78

HTTPD (Apache) ติดตั้ง Web server ( httpd ) [ root@server 1 ~]# yum - y install httpd ก าหนดให้ HTTPD ท างานทุกครั้งที่มีการ Reboot เครื่อง [root@server 1 ~]# systemctl enable httpd ท าการเปิดใช้งาน HTTPD [root@server 1 ~]# systemctl start httpd 78

หน้า 79

HTTPD (Apache) ตรวจสอบสถานะของ HTTPD [root@server 1 ~]# systemctl status httpd 79

หน้า 80

HTTPD (Apache) ตรวจสอบสถานะของ HTTPD [root@server 1 ~]# netstat - antp 80

หน้า 81

HTTPD (Apache) ทดสอบเข้าใช้งานผ่าน Web browser 81

หน้า 82

HTTPD (Apache) + PHP ท าการติดตั้ง PHP [root@server 1 ~]# yum - y install php จากนั้นท าการ restart HTTPD [root@server 1 ~]# systemctl restart httpd 82

หน้า 83

HTTPD (Apache) ทดสอบ PHP [root@server 1 ~]# echo "<? php echo PHP_VERSION; ?>" > / var /www/ html / phpversion.php 83

หน้า 84

HTTPD (Apache) + PHP + MariaDB การท าให้ HTTPD Connect Database ด้วย PHP [root@server 1 ~ ]# yum - y install php - mysql [root@server 1 ~]# systemctl restart httpd 84

หน้า 85

HTTPD (Apache) + PHP + MariaDB ทดสอบโดยสร้างไฟล์ต่อไปนี้ ไฟล์ / var /www/html/ dbuser.php <? php $ dbserver = "localhost"; $ dbuser = " wwwuser "; $ dbpassword = " AbCpassWoRD "; $ conn = mysql_connect ($ dbserver ,$ dbuser ,$ dbpassword ); ?> 85

หน้า 86

HTTPD (Apache) + PHP + MariaDB ทดสอบโดยสร้างไฟล์ต่อไปนี้ ไฟล์ / var /www/html/test - app.php <? php include ' dbuser.php '; if ($conn) { echo "Connected successfully"; } else { echo "Connection failed"; } mysql_close ($conn); ?> 86

หน้า 87

HTTPD (Apache) + PHP + MariaDB ทดสอบการใช้งานผ่าน Web browser 87

หน้า 88

HTTPD : Basic Hardening ปิดการแสดงหมายเลขรุ่นของ Apache และระบบปฏิบัติการ ดังตัวอย่าง 88

หน้า 89

HTTPD : Basic Hardening ปิดการแสดงหมายเลขรุ่นของ Apache และ ระบบปฏิบัติการ ให้ท าการแก้ไขไฟล์ / etc / httpd / conf / httpd.conf แล้วเพิ่ม Configure ต่อไปนี้เข้าไป ServerTokens Prod จากนั้นให้ restart httpd [root@server 1 conf ]# systemctl restart httpd 89

หน้า 90

HTTPD : Basic Hardening ผลการทดสอบ 90

หน้า 91

HTTPD : Basic Hardening ServerTokens แบบต่างๆ 91

หน้า 92

HTTPD : Basic Hardening ปิดการใช้งาน Directory Listing 92

หน้า 93

HTTPD : Basic Hardening ปิดการใช้งาน Directory Listing ให้ท าการแก้ไขไฟล์ / etc / httpd / conf / httpd.conf โดยให้แก้ดังนี้ < Directory "/ var /www/html "> Options Indexes FollowSymLinks แก้เป็น < Directory "/ var /www/html "> Options FollowSymLinks 93

หน้า 94

HTTPD : Basic Hardening จากนั้นท าการ restart httpd [root@server 1 includes]# systemctl restart httpd 94

หน้า 95

HTTPD : Basic Hardening การจ ากัดให้เฉพาะบาง IP เข้าถึง Directory ส าคัญโดย . htaccess - เปิดการใช้งาน . htaccess โดยแก้ไข / etc / httpd / conf / httpd.conf ค่าเดิม <Directory "/ var /www/html "> AllowOverride None แก้เป็น <Di r ectory "/ var /www/html "> AllowOverride All จากนั้นท าการ restart httpd [root@server 1 includes]# systemctl restart httpd 95

หน้า 96

HTTPD : Basic Hardening ท าการสร้างไฟล์ . htaccess ใน Directory ที่ต้องการ เช่น ถ้าต้องก าหนดให้เฉพาะ IP ชุด 192.168.14 5 .0 / 24 สามารถเข้าถึง http://IP.or.Domain/administrator/ ดังตัวอย่าง สร้างไฟล์ / var /www/html/administrator/. htaccess order deny,allow deny from all allow from 192.168.145.0 / 24 96

หน้า 97

HTTPD : Basic Hardening ซึ่งถ้า User มาจากชุด IP ที่เราก าหนดไว้ จะเข้าใช้งานได้ปกติ แต่ถ้า User มาจาก IP อื่นที่ไม่ได้อนุญาตไว้ ก็จะไม่สามารถเข้าใช้งานได้ ดังตัวอย่าง และจะมี Log เกิดขึ้นที่ / var /log/ httpd / error_log ดังนี้ [Sun Aug 07 13:35:28.186225 2016 ] [ access_compat:error ] [ pid 2786 ] [client 192.168.146.1: 59488 ] AH 01797 : client denied by server configuration: / var /www/html/administrator/ 97

หน้า 98

HTTPD : เปิดการใช้งาน HTTPS เปิดการใช้งาน HTTPS [ root@server 1 administrator]# yum - y install mod_ssl [root@server 1 administrator]# systemctl restart httpd ตรวจสอบการท างาน [root@server 1 administrator]# netstat - ant 98

หน้า 99

HTTPD : Basic Hardening ทดสอบเข้าใช้งานผ่าน Web browser 99

หน้า 100

HTTPD : Redirect Users to HTTPS สร้างไฟล์ . htaccess ในต าแหน่ง Directory ที่ต้องการให้ Redirect ไป HTTPS โดยใน ตัวอย่างนี้จะท าการ Redirect ทุกหน้าไปที่ HTTPS จึงจะท าการสร้างไฟล์ที่ Root ของ เวป ที่ / var /www/html/. htaccess RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} จากนั้นท าการทดสอบการใช้งาน 100

หน้า 101

FTP server ติดตั้ง FTP service โดย vsftpd [root@server 1 html]# yum - y install vsftpd ก าหนดให้ VSFTPD ท างานทุกครั้งที่ Reboot [root@server 1 html]# systemctl enable vsftpd เปิดการใช้งาน VSFTPD [root@server 1 html ]# systemctl start vsftpd 101

หน้า 102

FTP server ตรวจสอบการท างานของ VSFTPD [root@server 1 html]# systemctl status vsftpd [ root@server 1 html]# netstat - antp 102

หน้า 103

FTP server: Basic Hardening แก้ไขไฟล์ / etc / vsftpd / vsftpd.conf ดังตัวอย่าง anonymous_enable =NO chroot_local_user =YES allow_writeable_chroot =YES pasv_enable =YES port_enable =YES pasv_max_port = 10029 pasv_min_port = 10020 103

หน้า 104

FTP server with SSL ตัวอย่าง FTP ที่ไม่มี SSL 104

หน้า 105

FTP server with SSL เริ่มด้วยการสร้าง Server Key และ Server Certificate ( ในกรณีที่ยังไม่มี ) openssl req - x 509 - nodes - days 365 - newkey rsa: 1024 - keyout / etc / vsftpd / vsftpd.pem - out / etc / vsftpd / vsftpd.pem 105

หน้า 106

FTP server with SSL แก้ไขไฟล์ / etc / vsftpd / vsftpd.conf โดยเพิ่ม Configuration ต่อไปนี้ ssl_enable =YES rsa_cert_file =/ etc / vsftpd / vsftpd.pem rsa_private_key_file =/ etc / vsftpd / vsftpd.pem allow_anon_ssl =NO force_local_data_ssl =YES force_local_logins_ssl =YES ssl_tlsv 1 =YES ssl_sslv 2 =YES ssl_sslv 3 =YES require_ssl_reuse =NO ssl_ciphers =HIGH 106

หน้า 107

FTP server with SSL ทดสอบใช้งาน FTP ผ่าน SSL 107

หน้า 108

FTP server with SSL ทดสอบโดยการดัก traffic FTP 108

หน้า 109

FTP server with SSL ทดสอบ Login FTP โดยไม่ผ่าน SSL 109

หน้า 110

110 Questions?

ข้อความถอดจากไฟล์ต้นฉบับโดยอัตโนมัติ อาจมีข้อผิดพลาด โปรดยึดต้นฉบับของหน่วยงาน