אנדרואיד

אבטחה מאובטחת עם בואו להצפין באובונטו 18.04

תוכן עניינים:

Anonim

בואו להצפין הוא רשות אישורים שנוצרה על ידי קבוצת המחקר לאבטחה באינטרנט (ISRG). הוא מספק אישורי SSL בחינם בתהליך אוטומטי לחלוטין שנועד לחסל יצירת, אימות, התקנה וחידוש אישורים ידניים.

אישורים שהונפקו על ידי Let's Encrypt הם מהימנים על ידי כל הדפדפנים הגדולים כיום.

במדריך זה אנו נספק הוראות שלב אחר שלב כיצד לאבטח את ה- Apache שלך ​​באמצעות Let's Encrypt באמצעות כלי certbot באובונטו 18.04.

תנאים מוקדמים

וודא כי עמדת בתנאים המוקדמים הבאים לפני שתמשיך במדריך זה:

  • שם דומיין שמצביע על IP השרת הציבורי שלך. אנו נשתמש ב- example.com . יש לך Apache המותקן עם מארח וירטואלי של Apache עבור התחום שלך.

התקן את Certbot

Certbot הוא כלי מלא ובקלות לשימוש המאפשר להפוך את המשימות לאוטומציה להשגת וחידוש בואו להצפין אישורי SSL ולהגדרת שרתי אינטרנט. חבילת certbot כלולה במאגרי ברירת המחדל של אובונטו.

עדכן את רשימת החבילות והתקן את חבילת certbot:

sudo apt update sudo apt install certbot

צור קבוצת Dh (דיפי-הלמן) חזקה

החלפת מפתחות Diffie – Hellman (DH) היא שיטה להחלפה מאובטחת של מפתחות קריפטוגרפיים דרך ערוץ תקשורת לא מאובטח. אנו הולכים ליצור קבוצה חדשה של פרמטרים DH של 2048 ביט לחיזוק האבטחה:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048 אם תרצה, אתה יכול לשנות את הגודל עד 4096 ביטים, אך במקרה כזה, הדור עשוי לארוך יותר מ 30 דקות, תלוי באנטרופיה של המערכת.

קבלת אישור בואו להצפין SSL

כדי להשיג אישור SSL לתחום, אנו נשתמש בתוסף Webroot שעובד על ידי יצירת קובץ זמני לאימות הדומיין המבוקש בספרייה ${webroot-path}/.well-known/acme-challenge . שרת בואו להצפין מבצע בקשות HTTP לקובץ הזמני כדי לאמת כי הדומיין המבוקש פותר לשרת בו פועל certbot.

כדי להפוך את זה פשוט יותר אנו למפות את כל בקשות ה- HTTP עבור. .well-known/acme-challenge לספריה יחידה, /var/lib/letsencrypt .

הפקודות הבאות תיצור את הספרייה ותהיה ניתנת לכתיבה לשרת Apache.

sudo mkdir -p /var/lib/letsencrypt/.well-known sudo chgrp www-data /var/lib/letsencrypt sudo chmod g+s /var/lib/letsencrypt

כדי למנוע כפילויות של קוד, צור את שני קטעי התצורה הבאים:

/etc/apache2/conf-available/letsencrypt.conf

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS /etc/apache2/conf-available/ssl-params.conf

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" # Requires Apache >= 2.4.11 SSLSessionTickets Off SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"

הקטע שלמעלה משתמש בשבבים המומלצים על ידי Cipherli.st, מאפשר סיכות OCSP, HTTP Strict Transport Security (HSTS) ואכיפת מעט כותרות HTTP ממוקדות אבטחה.

לפני שתפעיל את קבצי התצורה, וודא ש- mod_ssl וגם mod_headers מופעלים על ידי הנפקה:

sudo a2enmod headers

בשלב הבא, הפעל את קבצי תצורת SSL על ידי הפעלת הפקודות הבאות:

sudo a2enconf letsencrypt sudo a2enconf ssl-params

הפעל את מודול HTTP / 2, אשר יהפוך את האתרים שלך למהירים וחזקים יותר:

sudo a2enmod

טען מחדש את תצורת Apache כדי שינויים ייכנסו לתוקף:

sudo systemctl reload apache2

כעת נוכל להפעיל את הכלי Certbot עם התוסף webroot ולקבל את קבצי אישור ה- SSL על ידי הקלדה:

sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com

אם אישור ה- SSL מתקבל בהצלחה, certbot ידפיס את ההודעה הבאה:

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-10-28. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF:

כעת, לאחר שיש לך את קבצי האישורים, ערוך את תצורת המארח הווירטואלי של הדומיין שלך באופן הבא:

/etc/apache2/sites-available/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration

עם התצורה שלמעלה, אנו מכריחים HTTPS ומפנים מחדש מגירסת www לגירסה שאינה www. אל תהסס להתאים את התצורה בהתאם לצרכים שלך.

טען מחדש את שירות Apache כדי שינויים ייכנסו לתוקף:

sudo systemctl reload apache2

כעת תוכל לפתוח את האתר שלך באמצעות https:// ותבחין בסמל נעילה ירוקה.

חידוש אוטומטי של בואו להצפין אישור SSL

תעודות בואו להצפין תקפות למשך 90 יום. כדי לחדש אוטומטית את האישורים לפני שפג תוקפם, חבילת certbot יוצרת מציצה הפועלת פעמיים ביום ומחדשת אוטומטית כל תעודה 30 יום לפני תפוגה.

לאחר שתתחדש האישור עלינו לטעון מחדש את שירות Apache. הוסף --renew-hook "systemctl reload apache2" לקובץ /etc/cron.d/certbot כך שהוא ייראה כך:

/etc/cron.d/certbot

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload apache2"

כדי לבדוק את תהליך החידוש, אתה יכול להשתמש במתג --dry-run :

sudo certbot renew --dry-run

אם אין שגיאות, פירוש הדבר שתהליך החידוש היה מוצלח.

סיכום

במדריך זה השתמשת ב- Certcot לקוח של Encrypt לקוח, כדי להוריד תעודות SSL עבור התחום שלך. יצרת גם קטעי Apache כדי למנוע כפילות של קוד והגדרת את Apache לשימוש בתעודות. בסוף ההדרכה, הגדרת עבודת גמילה לחידוש אישורים אוטומטית.

apache אובונטו בואו להצפין את certbot ssl

פוסט זה הוא חלק מהסדרה כיצד להתקין-מנורה-ערימה-באובונטו-18-04.

פוסטים אחרים בסדרה זו:

• כיצד להתקין אפאצ'י באובונטו 18.04 • כיצד להתקין מארחים וירטואליים של אפאצ'י באובונטו 18.04 • אבטחה של Apache עם בואו להצפין באובונטו 18.04 • כיצד להתקין את MySQL באובונטו 18.04 • כיצד להתקין PHP באובונטו 18.04