{"id":2774,"date":"2023-09-10T16:07:22","date_gmt":"2023-09-10T14:07:22","guid":{"rendered":"https:\/\/linux-bibel.at\/?p=2774"},"modified":"2023-09-10T16:07:24","modified_gmt":"2023-09-10T14:07:24","slug":"postfix-der-mailserver-unter-linux","status":"publish","type":"post","link":"https:\/\/linux-bibel.at\/index.php\/2023\/09\/10\/postfix-der-mailserver-unter-linux\/","title":{"rendered":"Postfix &#8211; der Mailserver unter Linux"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Linux-Benutzer der \u00e4lteren Generationen kennen sie noch &#8211; die root-Mails. Macht das System irgendwo Probleme &#8211; sieht man beim Einloggen am Terminal &#8211; &#8222;<em>Sie haben neue Mails<\/em>&#8220; (<em>oder \u00e4hnlich<\/em>). Hat eine vorkonfigurierte Software automatisch ihre Arbeit abgeschlossen, bekommt man eine root-Mail mit deren Ausgabe &#8211; etwa ein Virenscanner, ein Rootkit-J\u00e4ger, eine Einbruchserkennung und \u00e4hnliche Software, aber auch viele anderen Anwendungen w\u00fcrden root-Mails erstellen und senden &#8211; wenn denn ein sogenannter&nbsp;<strong>MTA<\/strong>&nbsp;(<em>ein Mail Transport Agent<\/em>) installiert ist. Ist dies nicht der Fall, kann man sich die Log-Dateien im ganzen System zusammenklauben, was auch nicht sonderlich erfreulich ist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ich habe gerade heute einen Rechner mit Debian f\u00fcr einen Kollegen installiert &#8211; er h\u00e4tte gerne solche root-Mails, doch auch Debian installiert heute automatisch keinen MTA mehr. Gerade auf einem Server ohne grafische Oberfl\u00e4che ist ein solcher jedoch von Vorteil.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Der wohl bekannteste MTA unter Linux ist Postfix &#8211; und dessen Installation und Konfiguration sehen wir uns in diesem Beitrag unter auf Debian basierenden Linux-Distributionen an.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Postfix installieren<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Unter auf Debian basierenden Linux-Distributionen installieren Sie diese Software wie \u00fcblich ganz einfach \u00fcber die\u00a0Paket-Verwaltung\u00a0durch das Paket &#8222;<strong>postfix<\/strong>&#8222;. Es finden sich noch weitere Pakete f\u00fcr die Installation von Postfix, die etwa mit Datenbanken interagieren k\u00f6nnen, dies ist f\u00fcr normale Zwecke jedoch meist absolut unn\u00f6tig.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Die einfachste Installation erfolgt als\u00a0root\u00a0am\u00a0Terminal\u00a0mit den Befehlen:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update\napt install postfix<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Es startet nicht nur die Installation, sondern auch die Konfiguration:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1024x576.jpg\" alt=\"\" class=\"wp-image-2775\" srcset=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1024x576.jpg 1024w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-300x169.jpg 300w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-768x432.jpg 768w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1536x864.jpg 1536w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Zu Beginn erhalten Sie erst einmal einige Informationen, mit\u00a0<strong><kbd>Eingabe<\/kbd><\/strong>\u00a0gehen Sie weiter &#8211; lesen sollten Sie die Information nat\u00fcrlich schon:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1-1024x576.jpg\" alt=\"\" class=\"wp-image-2776\" srcset=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1-1024x576.jpg 1024w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1-300x169.jpg 300w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1-768x432.jpg 768w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1-1536x864.jpg 1536w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-1.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Die erste wichtige Konfiguration &#8211; wie wollen Sie Postfix nutzen? Haben Sie die Informationen zuvor gelesen, wissen Sie, was Sie jetzt ausw\u00e4hlen sollten. Zur Navigation nutzen Sie die\u00a0<strong><kbd>Pfeiltasten<\/kbd><\/strong>\u00a0(<em>auf \/ ab<\/em>), zum Wechseln auf die Schalter darunter die\u00a0<strong><kbd>Tabulator<\/kbd><\/strong>-Taste, zum Best\u00e4tigen wieder\u00a0<strong><kbd>Eingabe<\/kbd><\/strong>. Hier noch einmal kurz die M\u00f6glichkeiten und eine kurze Beschreibung:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Internet-Site<\/strong>&nbsp;&#8211; Der Server versendet und empf\u00e4ngt E-Mails direkt, hierzu ist eine fixe IP-Adresse n\u00f6tig &#8211; etwa f\u00fcr Server im Internet.<\/li>\n\n\n\n<li><strong>Internet mit Smarthost<\/strong>&nbsp;&#8211; Der Server versendet \u00fcber einen anderen Mail-Server, etwa &#8211; wenn man keine statische (fixe) IP-Adresse hat. Ohne statische IP-Adresse wird der eigene Mail-Server schnell als Spam-Mail-Server verurteilt.<\/li>\n\n\n\n<li><strong>Satellite System<\/strong>&nbsp;&#8211; Wie &#8222;<em>Internet mit Smarthost<\/em>&#8222;, jedoch werden nur E-Mails versendet &#8211; aber keine E-Mails empfangen. Dies kann etwa n\u00fctzlich sein, um root-Mails \u00fcber einen anderen Mail-Server an eine beliebige Adresse zu versenden.<\/li>\n\n\n\n<li><strong>Nur lokal<\/strong>&nbsp;&#8211; E-Mails k\u00f6nnen versendet und empfangen werden, jedoch nur am lokalen Rechner. Bestens geeignet, wenn Sie die Mails direkt am selben System lesen m\u00f6chten. Auch k\u00f6nnen Sie Mails an andere Benutzer desselben Rechners senden.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2-1024x576.jpg\" alt=\"\" class=\"wp-image-2777\" srcset=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2-1024x576.jpg 1024w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2-300x169.jpg 300w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2-768x432.jpg 768w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2-1536x864.jpg 1536w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-2.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Weiter geht es mit dem Mail-Namen des Rechners \/ Systems. Im Grunde genommen besteht der Mail-Name aus dem Hostnamen, haben Sie ein eigenes Netzwerk &#8211; und Sie m\u00f6chten, dass auch andere Rechner den Mail-Server benutzen, geben Sie auch die Domain Ihres Netzwerkes an. M\u00f6chten Sie diese Konfiguration wiederholen, nutzen Sie den Befehl:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dpkg-reconfigure postfix<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Je nach Auswahl &#8211; wie Sie Postfix nutzen m\u00f6chten, wird es noch weitere Nachfragen geben. Etwa, welche IP-Adressen den Mail-Server noch benutzen d\u00fcrfen, welcher SMTP-Server genutzt werden soll.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dies w\u00e4re erst einmal die Grundkonfiguration gewesen &#8211; jetzt gehen wir weiter.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">M\u00fcssen Sie sich auf einem Smarthost (<em>SMTP<\/em>) verifizieren &#8211; gehen wir erst einmal an die Datei &#8222;<em>\/etc\/postfix\/<strong>main.cf<\/strong><\/em>&#8220; &#8211; etwa mit dem Terminal-Editor Nano oder Vim (<em>nat\u00fcrlich als root<\/em>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/postfix\/main.cf\nvim \/etc\/postfix\/main.cf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Hier f\u00fcgen Sie am Ende der Datei folgende neuen Zeilen ein:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp_sasl_auth_enable = yes\nsmtp_sasl_security_options = noplaintext noanonymous\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Die Datei wird gespeichert, weiter geht es mit der Passwort-Datei:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/postfix\/sasl_passwort\nvim \/etc\/postfiix\/sasl_passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Hier f\u00fcgen Sie erst einmal den SMTP-Server ein &#8211; etwa &#8222;<strong>smtp.google.com<\/strong>&#8220; und geben\u00a0<strong>Benutzernamen<\/strong>\u00a0und\u00a0<strong>Passwort<\/strong>\u00a0an:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp.google.com Benutzername:Passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Diese Datei sichern wir ab:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 600 \/etc\/postfix\/sasl_passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Jetzt erstellen wir die Datenbank f\u00fcr das Passwort:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postmap hash:\/etc\/postfix\/sasl_passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Meist gilt es sich beim SMTP-Server zu authentifizieren, hierzu dient die Mail-Adresse &#8211; man f\u00fcgt in der &#8222;<strong>main.cf<\/strong>&#8220; eine weitere Zeile hinzu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sender_maps = hash:\/etc\/postfix\/sender<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Jetzt legen wir die Datei an:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/postfix\/sender\nvim \/etc\/postfix\/sender<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Hier f\u00fcgt man jetzt pro Zeile eine Mail-Adresse ein, f\u00fcr jeden Zugang ben\u00f6tigt man eine Zeile &#8211; etwa:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>robert robert.goedl@gmail.com\nroot robert.goedl@gmail.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Die Datei wird gespeichert, anschlie\u00dfend \u00fcbernehmen wir die Konfiguration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postmap \/etc\/postfix\/sender<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Jetzt gilt es die Anmeldung beim SMTP-Server noch zu verschl\u00fcsseln, die meisten Anbieter erlauben keine unverschl\u00fcsselte Daten\u00fcbertragung mehr (<em>zum Gl\u00fcck<\/em>). Hierzu f\u00fcgen wir in der &#8222;<strong>main.cf<\/strong>&#8220; folgende Zeile hinzu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp_tls_security_level = may<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Jetzt k\u00f6nnen wir versuchen, eine Testmail zu senden:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Testmail\" | mail -s \"Betreff\" robert.goedl@gamil.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Manche SMTP-Server verlangen spezielle Optionen &#8211; hier einige bekannte, diese f\u00fcgen Sie in die &#8222;<strong>main.cf<\/strong>&#8220; ein:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AOL<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>relayhost = &#91;mail.gmx.net:587]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>GMX<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In die &#8222;<strong>sasl_passwort<\/strong>&#8222;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mail.gmx.net mail.adresse@gmx.de:Passwort<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In die &#8222;<strong>main.cf<\/strong>&#8222;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias_database = hash:\/etc\/aliases\ninet_interfaces = loopback-only\nmailbox_size_limit = 0\nrelayhost = mail.gmx.net:587\nsender_canonical_maps = hash:\/etc\/postfix\/sender\nsmtp_generic_maps = hash:\/etc\/postfix\/generic\nsmtp_sasl_auth_enable = yes\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwort\nsmtp_sasl_security_options = noanonymous\nsmtp_tls_security_level = encrypt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Web.de<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp_sasl_security_options = noanonymous<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Gmail<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp_tls_security_level = may\nsmtp_sasl_security_options = noanonymous<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Wollen wir uns die root-Mails nur am lokalen Rechner zustellen lassen, brauchen wir nat\u00fcrlich keinen SMTP-Server als Smarthost. Wir erhalten ohne jede weitere Konfiguration unter &#8222;<em>\/var\/mail\/<strong>root<\/strong><\/em>&#8220; unsere Nachrichten &#8211; nat\u00fcrlich als root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>less \/var\/mail\/root<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3-1024x576.jpg\" alt=\"\" class=\"wp-image-2778\" srcset=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3-1024x576.jpg 1024w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3-300x169.jpg 300w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3-768x432.jpg 768w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3-1536x864.jpg 1536w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/09\/postfix-3.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Im Screenshot oben etwa der automatische Check von\u00a0Chkrootkit. Um einiges komfortabler ist nat\u00fcrlich ein Mail-Client &#8211; nat\u00fcrlich am einfachsten gleich einer f\u00fcr das Terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install mailutils<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Jetzt \u00f6ffnen wir Mailx als root am Terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mailx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Sie finden jetzt alle Mails aufgelistet, Sie markieren Mails mit den\u00a0<strong><kbd>Pfeiltasten<\/kbd><\/strong>, \u00f6ffnen mit\u00a0<strong><kbd>Eingabe<\/kbd><\/strong>, schlie\u00dfen mit\u00a0<strong><kbd>q<\/kbd><\/strong>\u00a0und beenden die Software mit\u00a0<strong><kbd>q<\/kbd><\/strong>.<\/p>\n<div class=\"pld-like-dislike-wrap pld-custom\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir\" data-post-id=\"2774\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Hoch.png\" alt=\"Gef\u00e4llt mir\" \/>\r\n            <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">1    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir nicht\" data-post-id=\"2774\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Runter.png\" alt=\"Gef\u00e4llt mir nicht\" \/>\r\n            <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Linux-Benutzer der \u00e4lteren Generationen kennen sie noch &#8211; die root-Mails. Macht das System irgendwo Probleme &#8211; sieht man beim Einloggen am Terminal &#8211; &#8222;Sie haben neue Mails&#8220; (oder \u00e4hnlich). Hat eine vorkonfigurierte Software automatisch ihre Arbeit abgeschlossen, bekommt man eine root-Mail mit deren Ausgabe &#8211; etwa ein Virenscanner, ein Rootkit-J\u00e4ger, eine Einbruchserkennung und \u00e4hnliche Software, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2777,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,308],"tags":[39,310],"class_list":["post-2774","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-netzwerk","category-server","tag-netzwerk","tag-server"],"_links":{"self":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/2774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/comments?post=2774"}],"version-history":[{"count":1,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/2774\/revisions"}],"predecessor-version":[{"id":2779,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/2774\/revisions\/2779"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media\/2777"}],"wp:attachment":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media?parent=2774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/categories?post=2774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/tags?post=2774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}