Open Source How-To

You are here: Home > 4. Ubuntu 18.04 Server > ติดตั้ง ssl-cert บน ubuntu 18.04 server

ติดตั้ง ssl-cert บน ubuntu 18.04 server

 
 

บันทึกนี้ปรับปรุงล่าสุดเมื่อวันที่ 2-10-2561
ดูแลโดย WIBOON

 

  • โดยทั่วไปแล้ว เรามักไม่ได้เป็นผู้ติดตั้งโปรแกรมนี้ แต่โปรแกรมนี้มักจะถูกติดตั้งไปพร้อม ๆ กับการติดตั้งโปรแกรม web server เช่น apache2 web server เป็นต้น
mama@ubuntu:~$ sudo apt install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
...
Do you want to continue? [Y/n] 
  • แต่เพื่อความเข้าใจ เราควรจะรู้ว่า นอกจากใช้กับ web server แล้ว บางทีโปรแกรมที่ต้องการใช้งานเรื่องความปลอดภัยแบบ TLS ก็ต้องใช้ แต่หากว่ายังไม่ได้ติดตั้งไว้ ก็จะทำให้ติดตั้งโปรแกรมดังกล่าวไม่ผ่าน เช่น LDAPS เป็นต้น
  • ssl-cert ถูกนำไปใช้เป็นค่า default โดยเรียกว่า Self-signed Certificate
  • หลังจากติดตั้งจะได้ไดเรกทอรี /etc/ssl และเกิด group ssl-cert และมีชื่อเรียกว่า ssl-cert-snakeoil

 

1.ติดตั้งโปรแกรม

mama@ubuntu:~$ sudo apt install ssl-cert

 

2.ตรวจสอบดู file permission และ file owner ในไดเรกทอรี /etc/ssl

mama@ubuntu:~$ ls -l /etc/ssl/
total 32
drwxr-xr-x 2 root root     16384 Oct  2 16:45 certs
-rw-r--r-- 1 root root     10771 Apr 26 00:03 openssl.cnf
drwx--x--- 2 root ssl-cert  4096 Oct  2 16:45 private


และไดเรกทอรี /etc/ssl/private/ ต้องใช้สิทธิ root จึงจะดูรายชื่อไฟล์ที่เก็บอยู่ได้ อย่างนี้แสดงว่าติดตั้งถูกต้อง

mama@ubuntu:~$ ls -l /etc/ssl/private/
ls: cannot open directory '/etc/ssl/private/': Permission denied
mama@ubuntu:~$ sudo ls -l /etc/ssl/private/
total 4
-rw-r----- 1 root ssl-cert 1708 Oct  2 16:45 ssl-cert-snakeoil.key

ตรวจสอบดูว่าในไดเรกทอรี /etc/ssl/certs มี cert ของบริษัทต่าง ๆ ซึ่งไดเรกทอรีนี้เปิดดูรายการไฟล์ได้

mama@ubuntu:~$ ls -l /etc/ssl/certs
total 612
.
.
lrwxrwxrwx 1 root root     69 Oct  2 10:15  COMODO_Certification_Authority.pem -> /usr/share/ca-certificates/mozilla/
COMODO_Certification_Authority.crt lrwxrwxrwx 1 root root 73 Oct 2 10:15 COMODO_ECC_Certification_Authority.pem -> /usr/share/ca-certificates/mozilla/
COMODO_ECC_Certification_Authority.crt lrwxrwxrwx 1 root root 73 Oct 2 10:15 COMODO_RSA_Certification_Authority.pem -> /usr/share/ca-certificates/mozilla/
COMODO_RSA_Certification_Authority.crt lrwxrwxrwx 1 root root 61 Oct 2 10:15 Cybertrust_Global_Root.pem -> /usr/share/ca-certificates/mozilla/
Cybertrust_Global_Root.crt . . .

 

3.ตัวอย่าง ssl-cert กับ apache2 web server
จะมีตัวอย่างบรรทัดการใช้งาน SSL อยู่ที่ไฟล์ /etc/apache2/sites-available/default-ssl.conf

                SSLEngine on
                #   A self-signed (snakeoil) certificate can be created by installing
                #   the ssl-cert package. See
                #   /usr/share/doc/apache2/README.Debian.gz for more info.
                #   If both key and certificate are stored in the same file, only the
                #   SSLCertificateFile directive is needed.
                SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
                SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
nach oben