אנדרואיד

אבטחה מאובטחת עם בואו להצפין ב- debian 9

Instalar Apache2, php, mySQL, git en Debian 9

Instalar Apache2, php, mySQL, git en Debian 9

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

Anonim

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

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

מדריך זה ינחה אתכם בתהליך של קבלת בואו להצפין בחינם באמצעות כלי certbot ב- Debian 9. כמו כן, נראה כיצד להגדיר את אפאצ'י לשימוש בתעודת SSL החדשה ולאפשר HTTP / 2.

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

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

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

התקן את Certbot

Certbot הוא כלי מלא ובקלות לשימוש המאפשר להפוך את המשימות לאוטומציה להשגת וחידוש Let's Encrypt SSL אישורים. חבילת certbot כלולה במאגרי ברירת המחדל של Debian.

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

sudo apt update sudo apt install certbot

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

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

כדי ליצור מערך חדש של פרמטרי DH של 2048 ביט DH:

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

קבלת אישור בואו להצפין 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

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

sudo a2enmod

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

sudo a2enconf letsencrypt sudo a2enconf ssl-params

טען מחדש את תצורת 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: IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2019-01-17. 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 lose your account credentials, you can recover through e-mails sent to [email protected]. - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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

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

סיכום

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

בוא נצפין certbot ssl - -

פוסט זה הוא חלק מהסדרה כיצד להתקין את LAMP Stack בסדרת Debian 9.

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

כיצד להתקין Apache ב- Debian 9 • כיצד להתקין PHP ב- Debian 9 • כיצד להתקין מארחים וירטואליים של Apache ב- Debian 9 • כיצד להתקין MariaDB ב- Debian 9 • Apache מאובטח עם קידוד בואו ב- Debian 9