Server mit Ubuntu 18.04
Auf einem VServer wurde eine Installation von Ubuntu 18.04 fällig.
Hier erst einmal Änderungen an der Konfiguration für einen Server mit Ubuntu 18.04:
Grundinstallation
Bevor man mit der eigentlichen Einrichtung beginnt, sollte man den Server unbedingt einmal neu starten.
Benötigt man einmal die Liste aller installierten Pakete, so bekommt man die mit
dpkg --get-selections
Leider steht dann immer noch install hinter dem Paketnamen, aber das lässt sich ja mit Suchen und Ersetzen beseitigen.
In den aktuellen Ubuntu-Versionen läuft das Starten und Stoppen der Netzwerkdienste systemctl, der klassische Runlevel-Editor funktioniert da teilweise auch noch, als Umleitung.
systemctl status|start|stop <daemon>.service systemctl enable|disable <daemon>.service
Am Ende der Installation sollte man daran denken, die Namensauflösung für die Strato-Server IP auf einen eigenen Namen zu setzen und nicht die Voreinstellung zu belassen. Manche Provider lehnen Mails von Absenderadressen ab, wenn noch der Standardname gesetzt ist.
Firewall
Gleich nach der ersten Übersicht ist mir aufgefallen, dass keinerlei Firewall aktiv ist. Bei Ubuntu ist dafür ufw installiert und muss noch aktiviert werden. Bei ufw kann man relativ komfortabel Ports sperren oder freigeben, teilweise sogar über vorkonfigurierte Pakete. Wichtig ist, dass man Port 22 freigibt, bevor man die Firewall aktiviert (https://help.ubuntu.com/lts/serverguide/firewall.html, http://www.savvyadmin.com/ubuntus-ufw/):
ufw allow OpenSSH ufw allow "Apache Full"
Wer kommt auf die blöde Idee einen Bezeichner mit Leerzeichen zu wählen?? Nun kann man die Firewall aktivieren mittels:
ufw enable
Würde es die App OpenSSH nicht geben, so würde man Port 22 freigeben mittels:
ufw allow 22
oder
ufw allow ssh
Die Apache App steht erst zur Verfügung, wenn man den Webserver installiert hat. Die Liste der aktuell verfügbaren Apps kann man abrufen mittels:
ufw app list
Um nicht die syslog-Datei mit den ganzen Firewall-Meldungen zu füllen habe ich noch die Datei /etc/rsyslog.d/20-ufw.conf editiert.
# Log kernel generated UFW log messages to file :msg,contains,"[UFW " /var/log/ufw.log # Uncomment the following to stop logging anything that matches the last rule. # Doing this will stop logging kernel generated UFW log messages to the file # normally containing kern.* messages (eg, /var/log/kern.log) & stop
Die letzte Zeile beginnt normalerweise mit einem Kommentarzeichen, dass nach Anweisung weg muss.
Erste Installationen
Ich habe mir dann noch gleich ein paar nützliche Hilfsmittel installiert:
apt install synaptic apt-xapian-index update-apt-xapian-index -vf
Installiert das grafische Tool zur Paketverwaltung. Dann kann ich relativ leicht nach Paketen suchen.
Auch grafische Tools lassen sich per ssh aufrufen, wenn man beim Start der Verbindung den Parameter -X mit angibt:
ssh -X root@mein-server.domain
Da ich schon häufiger Probleme mit den Festplatten hatte, sind mir die Smartmontools wichtig (bei VServern funktioniert das in der Regel nicht, das keine physikalischen Platten vorliegen):
apt install smartmontools
Der Aufruf von
smartctl -A /dev/sda
bzw.
smartctl -A /dev/sdb
Liefert mir die Information, dass die Festplatten schon 18470 Stunden gelaufen sind, also etwas mehr als zwei Jahre. Es gibt aber keine Reallocierten Sektoren und beide Platten haben die gleiche Laufzeit.
Im Netzwerk benötigt man dann oft auch whois Informationen
apt install whois
Datenbank
Zur Installation von Server und Client dient der folgende Aufruf:
apt install mysql-client mysql-server mysql-common
Ich habe dann die Konfigurationsdatei /etc/mysql/mysql.conf.d/mysqld.cnf ergänzt
#ergänzt von U.D. innodb_flush_log_at_trx_commit = 2
und die Datenbank neu gestartet. Den Datenbankzugriff sollte man nicht über das Netz erlauben, also auch in der Firewall den entsprechenden Port nicht öffnen. Die Datenbank wird ja in der Regel nur über lokale Anwendungen genutzt und über PHPMyAdmin administriert.
Apache-Webserver
Die folgenden grundlegenden Pakete habe ich installiert
apt install apache2 apache2-bin apache2-data apache2-doc apache2-utils
Dann ein paar Pakete für PHP
apt install libapache2-mod-php libapache2-mod-php7.2 php php-auth-sasl php-bz2 php-cli php-common php-db php-gd php-geoip php-gettext php-imap php-log php-mail apt install php-mbstring php-mdb2 php-mysql php-net-smtp php-net-socket php-pear php-phpseclib php-recode php-soap php-tcpdf php-xml php7.2 php7.2-bz2 php7.2-cli php7.2-common apt install php7.2-gd php7.2-imap php7.2-json php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-readline php7.2-recode php7.2-soap php7.2-xml php7.2-zip phpmyadmin
Da sind jetzt eine Reihe von Doppelungen drin, sowohl das Paket, als auch das Metapaket. Es ist aber das, was mir
dpkg --get-selections | grep php
liefert.
Laut https://www.thomaschristlieb.de/mehrere-php-versionen-auf-einem-linux-server-mit-php-fpm/ kann man eventuell php7 und php5 parallel betreiben.
Nun noch ein paar Perl-Pakete:
apt install libapache2-mod-perl2 libapache2-reload-perl libapparmor-perl libarchive-zip-perl libauthen-sasl-perl libbsd-resource-perl apt install libcairo-perl libcgi-fast-perl libcgi-pm-perl libdevel-symdump-perl libencode-locale-perl libfcgi-perl libfile-basedir-perl apt install libfile-desktopentry-perl libfile-listing-perl libfile-mimeinfo-perl libfont-afm-perl libgd-graph-perl libgd-perl libgd-text-perl apt install libglib-perl libgtk2-perl libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl apt install libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl apt install libimage-magick-perl libimage-magick-q16-perl libio-html-perl libio-socket-ssl-perl libipc-system-simple-perl liblocale-gettext-perl apt install liblwp-mediatypes-perl liblwp-protocol-https-perl libmailtools-perl libnet-dbus-perl libnet-http-perl libnet-smtp-ssl-perl apt install libnet-ssleay-perl libpango-perl libperl5.26:amd64 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl apt install libtie-ixhash-perl libtimedate-perl liburi-perl libwww-perl libwww-robotrules-perl libx11-protocol-perl libxml-parser-perl apt install libxml-twig-perl libxml-xpathengine-perl perl perl-base perl-modules-5.26 libdbi-perl libdbd-mysql libclass-dbi-mysql-perl
Nach erfolgter Konfiguration (s.u.) darf man nicht vergessen die notwendigen Ports in der Firewall frei zu geben:
ufw allow "Apache Full"
letsencrypt
Für die verschlüsselte Übertragung von Webseiten werden Zertifikate benötigt. Für die Installation gemäß http://www.debacher.de/ublog/2016/06/letsencrypt/ benötige ich git:
apt install git
für Typo3
Da ich viel mit Typo3 arbeite habe ich etwas an den PHP-Einstellungen gedreht in der /etc/php/7.0/apache2/php.ini:
post_max_size=10M upload_max_filesize=10M max_execution_time=240 max_input_vars = 1500
Typo3 benötigt unbedingt imagemagick (oder alternativ graphicsmagick)
apt install imagemagick imagemagick-doc
apt install graphicsmagick
/etc/apache2/sites-available/000-default.conf
Im ersten Schritt ändere ich einen Teil der Standardvorgaben in der Datei 000-default.conf. Der Name resultiert aus der Tatsache, dass der Apache die Dateien in alphabetischer Reihenfolge einliest. Diese Datei muss als erste eingelesen werden.
ServerAdmin Webmaster@<dummy>.de
ServerTokens Major
DocumentRoot /var/www/htdocs
Alias /groupoffice /var/www/htdocs/dummy
Alias /squirrelmail /var/www/htdocs/dummy
Alias /webmail /var/www/dummy
Alias /webstat /var/www/htdocs/webalizer
<Directory "/var/www/vhosts">
AllowOverride All
Options +FollowSymLinks
Require all granted
</Directory>
<IfModule mod_userdir.c>
UserDir disabled
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType text/xml "access plus 1 week"
</IfModule>
<IfModule mod_setenvif.c>
# SEO
BrowserMatchNoCase (mindUp|meanpathbot|seoscanners|AiHitBot|BLEXBot|DotBot|linkdexbot|MJ12bot|SEOkicks-Robot) ist_ein_bot
# Sammeln Backlinks & Links
BrowserMatchNoCase (exabot|Baidu|Haosou|Semrush|MegaIndex|AhrefsBot|BacklinkCrawler|dlcbot|spbot) ist_ein_bot
# Performance Testing
BrowserMatchNoCase (200PleaseBot|LoadTimeBot) ist_ein_bot
# BilderSuche
BrowserMatchNoCase (psbot|Yandex) ist_ein_bot
# Harvester & Marketing
BrowserMatchNoCase (XoviBot|CareerBot|GrapeshotCrawler|iCjobs|magpie-crawler|proximic) ist_ein_bot
# Nutzlos, Schlecht bzw. unbekannt
BrowserMatchNoCase (Ezooms|updown_tester|^Java) ist_ein_bot
# Per IP
SetEnvIfNoCase Remote_Addr (62\.138\.0\.25) ist_ein_bot
</IfModule>
<VirtualHost *:80>
ServerName default
UseCanonicalName Off
DocumentRoot /var/www/vhosts/default/httpdocs
Alias /groupoffice /var/www/htdocs/dummy
Alias /squirrelmail /var/www/htdocs/dummy
Alias /webmail /var/www/htdocs/dummy
Alias /postfixadmin /var/www/htdocs/dummy
Alias /phpMyAdmin /var/www/htdocs/dummy
Alias /roundcube /var/www/htdocs/dummy
Alias /.well-known /var/www/htdocs/.well-known
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory /var/www/vhosts/default/httpdocs>
AllowOverride All
Options None
Require all granted
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
# php_admin_value include_path "/var/www/htdocs/horde/pear:/var/www/htdocs:./"
# php_admin_value open_basedir "/var/www/htdocs:/tmp"
</IfModule>
</Directory>
</VirtualHost>
Der Ordner /var/www/htdocs/dummy ist hier ein leerer Dummy-Ordner, damit Zugriffe auf die entsprechenden Anwendungen ins Leere laufen. Natürlich müssen die in der Konfiguration genannten Pfade eingerichtet sein, also z.B. /var/www/vhosts/default/httpdocs und /var/www/vhosts/default/httpsdocs. Idealerweise sollte in den Ordnern auch eine Datei index.html liegen, um Fehlermeldungen zu vermeiden.
/etc/apache2/sites-available/default-ssl.conf
Damit die Konfiguration funktionieren kann muss, sofern das Modul SSL aktiviert wurde, an der angegebenen Stelle ein Zertifikat vorliegen. Es kann ruhig ein selbst erstelltes Zertifikat sein. Zur Vereinfachung ist bei Ubuntu gleich ein Zertifikat erstellt.
Dann habe ich mir die vorhandene Datei default-ssl.conf angepasst:
<IfModule mod_ssl.c>
<VirtualHost _default_:443 >
ServerAdmin webmaster@<dummy>.de
# ServerName default
UseCanonicalName Off
DocumentRoot /var/www/vhosts/default/httpsdocs
ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
Alias /groupoffice /var/www/htdocs/dummy
Alias /squirrelmail /var/www/htdocs/dummy
Alias /webmail /var/www/htdocs/dummy
Alias /postfixadmin /var/www/htdocs/dummy
Alias /phpMyAdmin /var/www/htdocs/dummy
Alias /roundcube /var/www/htdocs/dummy
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNUL
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/lib/cgi-bin/">
AllowOverride None
Options None
Require all denied
SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/vhosts/default/httpsdocs>
SSLRequireSSL
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
</IfModule>
Im Prinzip hätte ich auch beides in eine Datei packen können, aber es waren ja schon die beiden vorhanden.
Für alle weiteren https Seiten benutze ich Zertifikat von letsencrypt, aber für Stratoserver-Adressen erstellt letsencrypt keine Zertifikate mehr, weil es schon zuviele für xxx.stratoserver.net gibt.
/etc/apache2/sites-available/stratoserver.net.conf
Ich will einen Unterschied haben zwischen der Seite die bei einem Aufruf über die IP-Adresse oder eine nicht konfigurierte Domain erfolgt und der Seite, die über den korrekten Server-Namen geliefert wird. Daher ein virtueller Server für legale Namen.
<VirtualHost *:80>
ServerName h2656233.stratoserver.net
ServerAlias server3.netthelp.de
UseCanonicalName Off
DocumentRoot /var/www/vhosts/default/httpdocs
CustomLog /var/log/apache2/server_access_log combined
ErrorLog /var/log/apache2/server_error_log
ScriptAlias /cgi-bin/ "/var/www/vhosts/default/cgi-bin/"
Alias /phpMyAdmin /var/www/htdocs/phpMyAdmin
Alias /postfixadmin /var/www/htdocs/postfixadmin
Alias /webmail /var/www/roundcubemail
Alias /webstat /var/www/vhosts/default/webstat
Alias /roundcube /var/www/roundcubemail
Alias /roundcubemail /var/www/roundcubemail
Alias /.well-known /var/www/htdocs/.well-known
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory "/var/www/vhosts/cgi-bin/cgi-bin/">
AllowOverride None
Options None
Require all granted
</Directory>
<Directory /var/www/vhosts/default/httpdocs>
AllowOverride All
Options None
Require all granted
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
# php_admin_value include_path "/var/www/htdocs/horde/pear:/var/www/htdocs:./"
# php_admin_value open_basedir "/var/www/htdocs:/tmp"
</IfModule>
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443 >
ServerName h2656233.stratoserver.net
UseCanonicalName Off
DocumentRoot /var/www/vhosts/default/httpsdocs
CustomLog /var/log/apache2/server_access_log combined
ErrorLog /var/log/apache2/server_error_log
ScriptAlias /cgi-bin/ "/var/www/vhosts/default/cgi-bin/"
Alias /phpMyAdmin /var/www/htdocs/phpMyAdmin
Alias /postfixadmin /var/www/htdocs/postfixadmin
Alias /webmail /var/www/roundcubemail
Alias /webstat /var/www/vhosts/default/webstat
Alias /roundcube /var/www/roundcubemail
Alias /roundcubemail /var/www/roundcubemail
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNUL
SSLCertificateFile /etc/letsencrypt/live/server3.netthelp.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/server3.netthelp.de/privkey.pem
# SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
# SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
SSLProtocol All -SSLv2 -SSLv3
<Directory "/var/www/vhosts/default/cgi-bin/">
AllowOverride None
Options None
Require all granted
</Directory>
<Directory /var/www/vhosts/default/httpsdocs>
SSLRequireSSL
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>
</IfModule>
Vserver-Konfiguration
Für jeden weiteren VServer erfolgt die Konfiguration in /etc/apache2/vhosts/sites-available/<dummy>.conf nach folgendem System, wobei <dummy> durch z.B. den Domainnamen ersetzt wird. Das zugehörige Verzeichnis wird dann mit diesem Namen unterhalb von /var/www/vhosts/ angelegt.
<VirtualHost *:80>
ServerName www.<dummy>:80
ServerAlias <dummy>
ServerAlias <dummy>.server3.netthelp.de
UseCanonicalName Off
DocumentRoot /var/www/vhosts/<dummy>/httpdocs
CustomLog /var/log/apache2-vhosts.d/<dummy>_access.log combined
ErrorLog /var/log/apache2-vhosts.d/<dummy>_error.log
CustomLog /var/log/apache2/vhosts_access.log vhost_combined
ScriptAlias /cgi-bin/ /var/www/vhosts/<dummy>/cgi-bin/
Alias /webstat /var/www/vhosts/<dummy>/webstat
Alias /.well-known /var/www/htdocs/.well-known
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory /var/www/vhosts/<dummy>/httpdocs>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value include_path "/var/www/vhosts/<dummy>/httpdocs:.:/tmp:./:/usr/share/php5/PEAR/:/var/www/typo3src"
php_admin_value open_basedir "/var/www/vhosts/<dummy>/httpdocs:/tmp:.:/usr/share/php5/PEAR/:/var/www/typo3src"
php_value date.timezone "Europe/Berlin"
</IfModule>
<IfModule mod_python.c>
<Files ~ (\.py$)>
SetHandler python-program
PythonHandler mod_python.cgihandler
</Files>
</IfModule>
Options -Includes +ExecCGI
</Directory>
<Directory "/var/www/vhosts/<dummy>/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Require all granted
</Directory>
</VirtualHost>
# soll SSL aktiviert werden das _no entfernen
<IfModule mod_ssl_no.c>
<VirtualHost *:443>
ServerName www.<dummy>:443
ServerAlias <dummy>
UseCanonicalName Off
DocumentRoot /var/www/vhosts/<dummy>/httpdocs
CustomLog /var/log/apache2-vhosts.d/<dummy>_access.log combined
ErrorLog /var/log/apache2-vhosts.d/<dummy>_error.log
ScriptAlias /cgi-bin/ /var/www/vhosts/<dummy>/cgi-bin/
Alias /webstat /var/www/vhosts/<dummy>/webstat
SSLEngine on
<Directory /var/www/vhosts/<dummy>/httpdocs>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value include_path "/var/www/vhosts/<dummy>/httpdocs:.:/tmp:./:/usr/share/php5/PEAR/:/var/www/typo3src"
php_admin_value open_basedir "/var/www/vhosts/<dummy>/httpdocs:/tmp:.:/usr/share/php5/PEAR/:/var/www/typo3src"
php_value date.timezone "Europe/Berlin"
</IfModule>
<IfModule mod_python.c>
<Files ~ (\.py$)>
SetHandler python-program
PythonHandler mod_python.cgihandler
</Files>
</IfModule>
Options -Includes +ExecCGI
</Directory>
<Directory "/var/www/vhosts/<dummy>/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/<dummy>/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/<dummy>/privkey.pem
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCompression off
# Add six earth month HSTS header for all users...
# Header add Strict-Transport-Security "max-age=15768000"
SSLCipherSuite EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog /var/log/apache2-vhosts.d/<dummy>_ssl.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
Server-Module
Vorsichtshalber noch einmal ein paar Apache-Module aktivieren:
a2enmod perl a2enmod cgi a2enmod expires a2enmod headers a2enmod rewrite service apache2 restart
Verzeichnisse
Ein paar Verzeichnsse anlegen:
mkdir /var/log/ustat mkdir /srv/www mkdir /srv/www/typo3src mkdir /etc/webalizer.d mkdir /etc/logrotate.d/apache2-vhosts.d mkdir /etc/vhosts-sicherung.d mkdir /var/log/apache2-vhosts.d mkdir /var/vmail mkdir /var/log/vhosts-sicherung mkdir /home/tmp mkdir /home/server2-sicherungen
Mailsystem
Auf diesem Server soll es möglichst wenig Systembenutzer geben. Alle Mailadressen sollen also virtuell sein. Das System besteht aus folgenden Komponenten:
- Postfix
- Dovecot
- MySQL
- PostfixAdmin
Eine weitere wichtige Rolle hierbei spielt
- Roundcube
damit kann der virtuelle Benutzer Mailfilter bearbeiten und sein eigenes Passwort ändern.
Vorweg noch ein paar Informationen, die für das Testen ganz nützlich sind, man kann Mails in der Warteschlange (Abfrage mittels mailq) einzeln oder alle auf einen Schlag löschen.
postsuper -d ALL postsuper -d 52DBF19F51 (die komische Zeichenkette ist die Queue-ID die mailq mit ausgibt, hier wird diese Mail gelöscht)
Den Inhalt der Mail findet man in
/var/spool/postfix/deferred/5/52DBF19F51
Zustellinformationen bzw. Fehlermeldungen in
/var/spool/postfix/defer/5/52DBF19F51
oder per
postcat -vq 52DBF19F51 (zeigt die Mail mit der angegebenen ID)
Für die folgende Beschreibung wird ein Benutzer vmail (uid 303) und eine Gruppe vmail (gid 303) benutzt. Der Benutzer hat als Homeverzeichnis /var/vmail, wo dann auch die eingehenden Mails liegen.
Da Gruppe und Benutzer nicht vorhanden sind, legt man sie neu an:
groupadd -g 303 vmail mkdir /var/vmail chmod a+rxw /var/vmail useradd -d /var/vmail/ -s /bin/false -u 303 -g 303 vmail
Zunächst müssen einige Pakete installiert werden
apt install amavisd-new amavisd-new-postfix postfix postfix-mysql postfix-policyd-spf-python postfixadmin dovecot-antispam spamass-milter spamassassin spamc apt install roundcube roundcube-core roundcube-mysql roundcube-plugins roundcube-plugins-extra mailutils apt install dovecot-antispam dovecot-core dovecot-imapd dovecot-lmtpd dovecot-managesieved dovecot-mysql dovecot-pop3d dovecot-sieve dovecot-sqlite
Postfixadmin
Die Beschreibung geht aus von dem Programmpaket PostfixAdmin, welches die Verwaltung der virtuellen Mail-Adressen über ein kleines nettes Webfrontend erlaubt. Die Homepage dieses Programmes ist http://postfixadmin.sourceforge.net/. Das Programmpaket greift nur auf eine MySQL-Datenbank zu und nicht direkt in das Mailsystem ein.
Das Programm lässt sich ganz einfach über die Paketverwaltung installieren und liegt in der Version 2.3.7 vor (aktuell verfügbar ist 3.1: http://sourceforge.net/projects/postfixadmin/files/latest/download?source=files). Ich habe die aktuelle Version benutzt.
Das Programm wird im Verzeichnis /usr/share/postfixadmin eingerichtet und die Konfigurationsdateien sind auf /etc/postfixadmin verlinkt.
Datenbanken
Für das Tool wird eine Datenbank mit folgenden Tabellen benötigt (So legt Postfixadmin 3.0.2 sie über http://<server>/postfixadmin/setup.php an).
CREATE TABLE `admin` (
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`superadmin` tinyint(1) NOT NULL DEFAULT '0',
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Admins';
CREATE TABLE `alias` (
`address` varchar(255) NOT NULL,
`goto` text NOT NULL,
`domain` varchar(255) NOT NULL,
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`address`),
KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Aliases';
CREATE TABLE `alias_domain` (
`alias_domain` varchar(255) NOT NULL DEFAULT ,
`target_domain` varchar(255) NOT NULL DEFAULT ,
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`alias_domain`),
KEY `active` (`active`),
KEY `target_domain` (`target_domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Domain Aliases';
CREATE TABLE `config` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT ,
`value` varchar(20) NOT NULL DEFAULT ,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COMMENT='PostfixAdmin settings';
CREATE TABLE `domain` (
`domain` varchar(255) NOT NULL,
`description` varchar(255) CHARACTER SET utf8 NOT NULL,
`aliases` int(10) NOT NULL DEFAULT '0',
`mailboxes` int(10) NOT NULL DEFAULT '0',
`maxquota` bigint(20) NOT NULL DEFAULT '0',
`quota` bigint(20) NOT NULL DEFAULT '0',
`transport` varchar(255) NOT NULL,
`backupmx` tinyint(1) NOT NULL DEFAULT '0',
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Domains';
CREATE TABLE `domain_admins` (
`username` varchar(255) NOT NULL,
`domain` varchar(255) NOT NULL,
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Domain Admins';
CREATE TABLE `fetchmail` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`domain` varchar(255) DEFAULT ,
`mailbox` varchar(255) NOT NULL,
`src_server` varchar(255) NOT NULL,
`src_auth` enum('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any') DEFAULT NULL,
`src_user` varchar(255) NOT NULL,
`src_password` varchar(255) NOT NULL,
`src_folder` varchar(255) NOT NULL,
`poll_time` int(11) unsigned NOT NULL DEFAULT '10',
`fetchall` tinyint(1) unsigned NOT NULL DEFAULT '0',
`keep` tinyint(1) unsigned NOT NULL DEFAULT '0',
`protocol` enum('POP3','IMAP','POP2','ETRN','AUTO') DEFAULT NULL,
`usessl` tinyint(1) unsigned NOT NULL DEFAULT '0',
`sslcertck` tinyint(1) NOT NULL DEFAULT '0',
`sslcertpath` varchar(255) CHARACTER SET utf8 DEFAULT ,
`sslfingerprint` varchar(255) DEFAULT ,
`extra_options` text,
`returned_text` text,
`mda` varchar(255) NOT NULL,
`date` timestamp NOT NULL DEFAULT '1999-12-31 23:00:00',
`created` timestamp NOT NULL DEFAULT '1999-12-31 23:00:00',
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `log` (
`timestamp` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`username` varchar(255) NOT NULL,
`domain` varchar(255) NOT NULL,
`action` varchar(255) NOT NULL,
`data` text NOT NULL,
KEY `timestamp` (`timestamp`),
KEY `domain_timestamp` (`domain`,`timestamp`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Log';
CREATE TABLE `mailbox` (
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 NOT NULL,
`maildir` varchar(255) NOT NULL,
`quota` bigint(20) NOT NULL DEFAULT '0',
`local_part` varchar(255) NOT NULL,
`domain` varchar(255) NOT NULL,
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`username`),
KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Mailboxes';
CREATE TABLE `quota` (
`username` varchar(255) NOT NULL,
`path` varchar(100) NOT NULL,
`current` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`username`,`path`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `quota2` (
`username` varchar(100) NOT NULL,
`bytes` bigint(20) NOT NULL DEFAULT '0',
`messages` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `vacation` (
`email` varchar(255) NOT NULL,
`subject` varchar(255) CHARACTER SET utf8 NOT NULL,
`body` text CHARACTER SET utf8 NOT NULL,
`activefrom` timestamp NOT NULL DEFAULT '1999-12-31 23:00:00',
`activeuntil` timestamp NOT NULL DEFAULT '1999-12-31 23:00:00',
`cache` text NOT NULL,
`domain` varchar(255) NOT NULL,
`interval_time` int(11) NOT NULL DEFAULT '0',
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`email`),
KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';
CREATE TABLE `vacation_notification` (
`on_vacation` varchar(255) CHARACTER SET latin1 NOT NULL,
`notified` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ,
`notified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`on_vacation`,`notified`),
CONSTRAINT `vacation_notification_pkey` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Vacation Notifications';
Nicht alle Tabellen werden in meiner Konfiguration wirklich benutzt, aber es ist einfacher alle anzulegen.
/etc/postfixadmin/dbconfig.inc.php
Die Datenbankanbindung wird in der Ubuntu-Version über diese Datei konfiguriert.
<?php ## ## database access settings in php format ## automatically generated from /etc/dbconfig-common/postfixadmin.conf ## by /usr/sbin/dbconfig-generate-include ## ## by default this file is managed via ucf, so you shouldn't have to ## worry about manual changes being silently discarded. *however*, ## you'll probably also want to edit the configuration file mentioned ## above too. ## $dbuser='postfix'; $dbpass='assword'; $basepath=; $dbname='postfix'; $dbserver='localhost'; $dbport=; $dbtype='mysqli';
/etc/postfixadmin/config.inc.php
In dieser Datei der Ubuntu-Version sind viele Vor-Einstellungen anders, als ich es von meinen bisherigen Installationen gewohnt war. Hier ein paar Einstellungen, die wohl eine Rolle spielen:
$CONF['configured'] = true;
$CONF['setup_password'] = 'changeme';
$CONF['default_language'] = 'de';
$CONF['admin_email'] = 'postmaster@change-this-to-your.domain.tld';
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt';
$CONF['authlib_default_flavor'] = 'md5raw';
$CONF['dovecotpw'] = "/usr/bin/doveadm pw";
$CONF['min_password_length'] = 5;
$CONF['generate_password'] = 'NO';
$CONF['show_password'] = 'NO';
$CONF['page_size'] = '20';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['maildir_name_hook'] = 'NO';
$CONF['aliases'] = '10';
$CONF['mailboxes'] = '10';
$CONF['maxquota'] = '10240';
$CONF['quota'] = 'YES';
$CONF['quota_multiplier'] = '1024000';
$CONF['transport'] = 'NO';
$CONF['transport_options'] = array (
$CONF['transport_default'] = 'virtual';
$CONF['vacation'] = 'NO';
$CONF['vacation_domain'] = 'autoreply.change-this-to-your.domain.tld';
$CONF['vacation_control'] ='YES';
$CONF['vacation_control_admin'] = 'YES';
$CONF['alias_control'] = 'YES';
$CONF['alias_control_admin'] = 'YES';
$CONF['special_alias_control'] = 'NO';
$CONF['alias_goto_limit'] = '0';
$CONF['alias_domain'] = 'YES';
$CONF['backup'] = 'NO';
$CONF['sendmail'] = 'YES';
$CONF['logging'] = 'YES';
$CONF['fetchmail'] = 'YES';
$CONF['fetchmail_extra_options'] = 'NO';
$CONF['show_header_text'] = 'NO';
$CONF['header_text'] = ':: Postfix Admin ::';
$CONF['show_footer_text'] = 'YES';
$CONF['footer_text'] = 'Return to change-this-to-your.domain.tld';
$CONF['welcome_text'] = <<<EOM
Herzlich Willkommen,
zum Netthelp E-Mail Postfach.
Bei Fragen oder Problemen bitte
Uwe Debacher ansprechen
EOM;
$CONF['emailcheck_resolve_domain']='YES';
$CONF['show_status']='YES';
$CONF['show_status_key']='YES';
$CONF['show_status_text']=' ';
$CONF['show_undeliverable']='YES';
$CONF['show_undeliverable_color']='tomato';
$CONF['show_undeliverable_exceptions']=array("unixmail.domain.ext","exchangeserver.domain.ext","gmail.com");
$CONF['show_popimap']='YES';
$CONF['show_popimap_color']='darkgrey';
$CONF['show_custom_domains']=array("subdomain.domain.ext","domain2.ext");
$CONF['show_custom_colors']=array("lightgreen","lightblue");
$CONF['recipient_delimiter'] = "";
$CONF['create_mailbox_subdirs_prefix']='INBOX.';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';
Version 3.1
Die momentan aktuelle Version besitzt eine Reihe von neuen Funktionen. Ich habe mir das Archiv also heruntergeladen und nach /var/www/postfixadmin-3.1 installiert.
Schöne bei dieser Version ist die Konfiguration, die sich in einer Datei config.local.php sammeln lässt. Außerdem sind die Voreinstellungen deutlich dichter an meinen Wünschen. Es bleibt dann hier:
<?php $CONF['configured'] = true; // on submission it will be echoed out to you as a hashed value. $CONF['setup_password'] = '533a0f62bf8dcf073112eb0a0ed8929a:d85f0fe1081dccf9738b01fa7b377005b2ee8d9e'; $CONF['default_language'] = 'de'; // Database Config $CONF['database_type'] = 'mysqli'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = '<benutzer>'; $CONF['database_password'] = '<passwort>'; $CONF['database_name'] = '<datenbank>'; $CONF['admin_email'] = 'postmaster@netthelp.de'; $CONF['page_size'] = '20'; $CONF['default_aliases'] = array ( 'abuse' => 'abuse@netthelp.de', 'hostmaster' => 'hostmaster@netthelp.de', 'postmaster' => 'postmaster@netthelp.de', 'webmaster' => 'webmaster@netthelp.de' ); $CONF['quota'] = 'YES'; $CONF['footer_text'] = 'Zurück zu Netthelp.de'; $CONF['footer_link'] = 'http://netthelp.de'; // Welcome Message // This message is send to every newly created mailbox. // Change the text between EOM. $CONF['welcome_text'] = <<<EOM Herzlich Willkommen, zum Netthelp E-Mail Postfach. Bei Fragen oder Problemen bitte Uwe Debacher ansprechen EOM; $CONF['show_undeliverable_exceptions']=array("netthelp.de","debacher.de"); $CONF['used_quotas'] = 'YES'; $CONF['maxquota'] = '2048'; $CONF['domain_quota_default'] = '0';
Beim ersten Start tauchte eine Fehlermeldung auf:
ERROR: the templates_c directory doesn't exist or isn't writeable for the webserver
Ich habe dann dieses Verzeichnis angelegt und dem Webserver übereignet.
Version 3.2
Aktuell ist jetzt die Version 3.2, hier gibt es eine kleine Änderung zu beachten, der Alias-Eintrag in der VServer-Konfiguration muss jetzt auf das Unterverzeichnis public zeigen:
Alias /postfixadmin /var/www/postfixadmin-3.2/public
AmaVis
Diese Programm ist dazu da sich um Spam und Viren in EMails zu kümmern. Dazu arbeitet es mit Clamav und Spamassasin zusammen.
Für die Zusammenarbeit ist etwas Vorarbeit zu leisten, ich orientiere mich dabei an https://www.exratione.com/2016/05/a-mailserver-on-ubuntu-16-04-postfix-dovecot-mysql/
Zuerst werden die Programme gegenseitig in ihre Gruppen aufgenommen:
adduser clamav amavis adduser amavis clamav
Dann wird die Datei /etc/clamav/clamd.conf etwas angepasst
# Needed to allow things to work with Amavis, when both amavis and clamav # users are added to one another's groups. AllowSupplementaryGroups true
In der Datei /etc/amavis/conf.d/15-content_filter_mode müssen die Checks überhaupt erst einmal aktiviert werden, indem man die Kommentarzeichen vor den Zeilen entfernt.
use strict; # You can modify this file to re-enable SPAM checking through spamassassin # and to re-enable antivirus checking. # # Default antivirus checking mode # Please note, that anti-virus checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_virus_checks_maps = ( %bypass_virus_checks, @bypass_virus_checks_acl, $bypass_virus_checks_re); # # Default SPAM checking mode # Please note, that anti-spam checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_spam_checks_maps = ( %bypass_spam_checks, @bypass_spam_checks_acl, $bypass_spam_checks_re); 1; # ensure a defined return
Ob die Anpassung in /etc/default/spamassassin notwendig ist, wurde mir nicht ganz klar.
# Change to one to enable spamd ENABLED=1 # Cronjob # Set to anything but 0 to enable the cron job to automatically update # spamassassin's rules on a nightly basis CRON=1
Nun noch /etc/amavis/conf.d/50-user anpassen, damit die lokalen Domains aus der Datenbank genommen werden
use strict;
#
# Place your configuration directives here. They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#
# Three concurrent processes. This should fit into the RAM available on an
# AWS micro instance. This has to match the number of processes specified
# for Amavis in /etc/postfix/master.cf.
$max_servers = 3;
# Add spam info headers if at or above that level - this ensures they
# are always added.
$sa_tag_level_deflt = -9999;
# Check the database to see if mail is for local delivery, and thus
# should be spam checked.
@lookup_sql_dsn = (['DBI:mysql:database=postfix;host=127.0.0.1;port=3306', 'postfix', 'assword']);
$sql_select_policy = 'SELECT domain from domain WHERE CONCAT("@",domain) IN (%k)';
$sql_select_white_black_list = undef;
# Uncomment to bump up the log level when testing.
# $log_level = 2;
#------------ Do not modify anything below this line -------------
1; # ensure a defined return
Zum Abschluss die Dienste neu starten:
service clamav-freshclam restart service clamav-daemon restart service amavis restart service spamassassin restart
Dovecot
Unter http://www.debacher.de/wiki/Root-Server_mit_OpenSuSE_13.2#Dovecot habe ich die schrittweise Entwicklung meiner Dovecot-Konfiguration beschrieben. Diese Konfiguration passt weiterhin und befindet sich in der Datei /etc/dovecot/local.conf
disable_plaintext_auth = no
first_valid_uid = 303
mail_access_groups = postfix
mail_privileged_group = postfix
mail_location = maildir:/var/vmail/%d/%n
mail_home = /var/vmail/%d/%n/home
mail_plugins = $mail_plugins quota
passdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
plugin {
sieve = ~/.dovecot.sieve
sieve_dir = ~/sieve
}
dict {
sqluserquota = mysql:/etc/dovecot/dovecot-dict-sql-user.conf
}
protocols = imap pop3 lmtp sieve
ssl = yes
#ssl_cert = </etc/letsencrypt/live/server2.netthelp.de/fullchain.pem
#ssl_key = </etc/letsencrypt/live/server2.netthelp.de/privkey.pem
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
userdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
verbose_proctitle = yes
protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
mail_max_userip_connections = 5
}
protocol imap {
mail_max_userip_connections = 8
mail_plugins = $mail_plugins imap_quota
}
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
protocol lmtp {
mail_plugins = $mail_plugins sieve
}
service lmtp {
unix_listener lmtp {
#mode = 0666
}
unix_listener /var/spool/postfix/private/dovecot-lmtp {
#mode = 0666
user = postfix
group = postfix
}
}
service managesieve-login {
inet_listener sieve {
port = 4190
}
}
plugin {
#quota_rule = *:storage=1G
#quota_rule2 = Trash:storage=+100M
quota_grace = 10%%
quota_warning = storage=66%% quota-warning 66 %u
quota_warning2 = storage=80%% quota-warning 80 %u
quota_warning3 = storage=95%% quota-warning 95 %u
# quota = maildir:User quota:noenforcing
quota = dict:User Quota::noenforcing:proxy::sqluserquota
}
service quota-warning {
executable = script /usr/local/bin/quota-warning.sh
user = vmail
unix_listener quota-warning {
group = vmail
mode = 0660
user = vmail
}
}
service dict {
unix_listener dict {
mode = 0600
user = vmail
}
}
auth_mechanisms = plain login
#verbose_proctitle = no
#mail_debug = yes
#auth_debug = yes
auth_debug_passwords = yes
#auth_verbose = yes
auth_verbose_passwords = sha1
Zusätzlich habe ich die Authentisierung per pam deaktiviert, indem ich im Unterordner conf.d die Datei 10-auth.conf editiert und dort am Ende der Datei die einzig aktive Include-Zeile
!include auth-system.conf.ext
durch Voranstellen einer Raute deaktiviert habe. Das spart viel Zeit bei allen Authentifizierungen.
/etc/dovecot/dovecot-mysql.conf
Diese Datei musste ich etwas anpassen, da bei Ubuntu die Mysql-Socket Adresse etwas anders ist.
# Database driver: mysql, pgsql
driver = mysql
# Currently supported schemes include PLAIN, PLAIN-MD5, DIGEST-MD5, and CRYPT.
default_pass_scheme = CRYPT
# Database options
connect = host=/var/run/mysqld/mysqld.sock dbname=postfix user=postfix password=assword
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'
user_query = SELECT concat('maildir:/var/vmail/',maildir) as mail, \
303 AS uid, \
303 AS gid, \
CONCAT('*:bytes=', \
IF(mailbox.quota = 0, domain.maxquota*1024000, mailbox.quota)) \
as quota_rule \
FROM mailbox, domain \
WHERE username = '%u' AND mailbox.active = '1' AND \
domain.domain = '%d' AND domain.active = '1'
iterate_query = SELECT username as user FROM mailbox WHERE active ='1'
/etc/dovecot/dovecot-dict-sql-user.conf
Auch in dieser Datei muss ich der veränderten Socket Rechnung tragen
connect = host=/var/run/mysqld/mysqld.sock dbname=postfix user=postfix password=assword
map {
pattern = priv/quota/storage
table = quota2
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = quota2
username_field = username
value_field = messages
}
Erweiterungen
Manchmal taucht das Problem auf, dass auf dem Server mehrere Ordner für den gleichen Zwecke auftauchen, also z.B.
- .Junk
- .Spam
für unerwünschte Mails und
- .Trash
- .Papierkorb
für Müll
- .Gesendet
- .Sent
für versckickte Mails
Das kann man verhindern, indem man die Konfiguration der /etc/dovecot/conf.d/15-mailboxes.conf erweitert
namespace inbox {
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Spam {
special_use = \Junk
}
mailbox Trash {
special_use = \Trash
}
mailbox Papierkorb {
special_use = \Trash
}
....
}
Eventuell muss man hier auf die Eigenarten weiterer Client-Programme reagieren.
Roundcube
Dieses beliebte Webmail-Programm wird standardmäßig im Verzeichnis /var/lib/roundcube/ abgelegt. Hierbei werden einige Unterverzeichnisse und Dateien an andere Stellen verlinkt
- config -> /etc/roundcube
- program -> /usr/share/roundcube/program
- .htaccess -> /etc/roundcube/htaccess
- logs -> /var/log/roundcube
- robots.txt -> /usr/share/roundcube/robots.txt
Die Plugins finden sich im Verzeichnis /usr/share/roundcube/plugins/, wobei die Konfigurationsdateien, die auf /etc/roundcube/plugins/ verlinkt wurden, jeweils nahezu leer sind. Ein Muster findet sich dann jeweils unter /usr/share/roundcube/plugins/ in der Datei config.inc.php.dist
Also
cp /usr/share/roundcube/plugins/password/config.inc.php.dist /etc/roundcube/plugins/password/config.inc.php cp /usr/share/roundcube/plugins/managesieve/config.inc.php.dist /etc/roundcube/plugins/managesieve/config.inc.php
cp /usr/share/roundcube/plugins/zipdownload/config.inc.php.dist /etc/roundcube/plugins/zipdownload/config.inc.php cp /usr/share/roundcube/plugins/jqueryui/config.inc.php.dist /etc/roundcube/plugins/jqueryui/config.inc.php
Danach sind dann ein paar Dateien zu editieren.
/etc/roundcube/debian-db.php
<?php ## ## database access settings in php format ## automatically generated from /etc/dbconfig-common/roundcube.conf ## by /usr/sbin/dbconfig-generate-include ## ## by default this file is managed via ucf, so you shouldn't have to ## worry about manual changes being silently discarded. *however*, ## you'll probably also want to edit the configuration file mentioned ## above too. ## $dbuser='roundcube'; $dbpass='assword'; $basepath=; $dbname='roundcube'; $dbserver='localhost'; $dbport=; $dbtype='mysql';
/etc/roundcube/plugins/password/config.inc.php
ab Zeile 77
// SQL Driver options // ------------------ // PEAR database DSN for performing the query. By default // Roundcube DB settings are used. $config['password_db_dsn'] = 'mysql://postfix:assword@localhost/postfix'; // The SQL query used to change the password. // The query can contain the following macros that will be expanded as follows: // %p is replaced with the plaintext new password // %P is replaced with the crypted/hashed new password // according to configured password_method // %o is replaced with the old (current) password // %O is replaced with the crypted/hashed old (current) password // according to configured password_method // %h is replaced with the imap host (from the session info) // %u is replaced with the username (from the session info) // %l is replaced with the local part of the username // (in case the username is an email address) // %d is replaced with the domain part of the username // (in case the username is an email address) // Deprecated macros: // %c is replaced with the crypt version of the new password, MD5 if available // otherwise DES. More hash function can be enabled using the password_crypt_hash // configuration parameter. // %D is replaced with the dovecotpw-crypted version of the new password // %n is replaced with the hashed version of the new password // %q is replaced with the hashed password before the change // Escaping of macros is handled by this module. // Default: "SELECT update_passwd(%c, %u)" $config['password_query'] = 'UPDATE mailbox SET password=%c WHERE username=%u'; // By default the crypt() function which is used to create the %c // parameter uses the md5 algorithm (deprecated, use %P). // You can choose between: des, md5, blowfish, sha256, sha512. $config['password_crypt_hash'] = 'md5'; ...
/etc/roundcube/plugins/managesieve/config.inc.php
<?php // managesieve server port. When empty the port will be determined automatically // using getservbyname() function, with 4190 as a fallback. $config['managesieve_port'] = 4190;
/etc/roundcube/config.inc.php
In der hauptkonfigurationsdatei von Roundcube sind zwei Änderungen notwendig.
Ab Zeile 25
// The mail host chosen to perform the log-in. // Leave blank to show a textbox at login, give a list of hosts // to display a pulldown menu or set one host as string. // To use SSL/TLS connection, enter hostname with prefix ssl:// or tls:// // Supported replacement variables: // %n - hostname ($_SERVER['SERVER_NAME']) // %t - hostname without the first part // %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part) // %s - domain name after the '@' from e-mail address provided at login screen // For example %n = mail.domain.tld, %t = domain.tld $config['default_host'] = 'localhost';
Ab Zeile 74
// List of active plugins (in plugins/ directory) $config['plugins'] = array( 'archive', 'zipdownload', 'managesieve', 'password', );
Die Datenbankkonfiguration findet sich dann in der Datei /usr/share/roundcube/SQL/mysql.initial.sql
Postfix
Das zentrale Mailprogramm wird über die Dateien /etc/postfix/master.cf und /etc/postfix/main.cf konfiguriert. An der master.cf habe ich keinerlei Änderungen vorgenommen. Lediglich die main.cf habe ich nach meinen Anforderungen erweitert.
/etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = server3.netthelp.de
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, server3.netthelp.de, h2656233.stratoserver.net, localhost.stratoserver.net, localhost
relayhost =
#mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
content_filter = smtp-amavis:[localhost]:10024
policy-spf_time_limit = 3600s
relay_domains = $mydestination, hash:/etc/postfix/relay
#virtual_alias_domains = hash:/etc/postfix/virtual
#virtual_alias_maps = hash:/etc/postfix/virtual, hash:/var/lib/mailman/data/virtual-mailman, proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf, proxy:mysql:/etc/postfix/mysql_virtual_alias_domain_maps.cf,proxy:mysql:/etc/postfix/mysql_virtual_alias_domain_catchall_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf, proxy:mysql:/etc/postfix/mysql_virtual_alias_domain_maps.cf, proxy:mysql:/etc/postfix/mysql_virtual_alias_domain_catchall_maps.cf
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain =
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = no
smtp_sasl_security_options =
smtp_sasl_password_maps =
unknown_address_reject_code = 552
unknown_client_reject_code = 551
unknown_hostname_reject_code = 550
virtual_gid_maps = static:303
virtual_mailbox_base = /var/vmail/
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 0
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, proxy:mysql:/etc/postfix/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_minimum_uid = 303
virtual_transport = lmtp:unix:private/dovecot-lmtp
virtual_uid_maps = static:303
#maps_rbl_reject_code = 451
#canonical_maps = hash:/etc/postfix/canonical
#relocated_maps = hash:/etc/postfix/relocated
#sender_canonical_maps = hash:/etc/postfix/sender_canonical
#transport_maps = hash:/etc/postfix/transport
#mail_spool_directory = /var/mail
message_strip_characters = \0
defer_transports =
mailbox_command =
mailbox_transport =
mailbox_size_limit = 0
message_size_limit = 0
strict_8bitmime = no
strict_rfc821_envelopes = yes
smtpd_delay_reject = yes
smtpd_helo_required = yes
smtpd_client_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_rbl_client cbl.abuseat.org, reject_rbl_client ix.dnsbl.manitu.net, reject_rbl_client bl.spamcop.net, reject_rbl_client dul.dnsb
smtpd_helo_restrictions = permit_mynetworks, reject_invalid_hostname
smtpd_sender_restrictions = hash:/etc/postfix/access, reject_unknown_sender_domain
#smtpd_recipient_restrictions = , check_policy_service unix:private/policy-spf
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
# tls config
# eingehende Verbindungen
smtpd_use_tls = yes
smtpd_enforce_tls = no
# Obiges kann zusammengefasst werden zu smtpd_tls_security_level=may
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_mandatory_protocols=!SSLv2, !SSLv3
#tls_random_source = dev:/dev/urandom
#tls_random_prng_update_period = 3600s
# ausgehende Verbindungen
smtp_use_tls = yes
smtp_enforce_tls = no
# Obiges kann zusammengefasst werden zu smtp_tls_security_level=may
smtp_tls_note_starttls_offer = yes
smtp_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtp_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
#smtp_tls_key_file = /etc/letsencrypt/live/server3.netthelp.de/privkey.pem
#smtp_tls_cert_file = /etc/letsencrypt/live/server3.netthelp.de/fullchain.pem
smtp_tls_loglevel = 1
smtp_tls_mandatory_protocols=!SSLv2, !SSLv3
# Limits - neu ab 17.1.17 gegen Spam
smtpd_client_message_rate_limit = 50
smtpd_client_connection_rate_limit = 10
smtpd_client_recipient_rate_limit = 50
smtpd_client_connection_count_limit = 25
bounce_queue_lifetime = 3d
maximal_queue_lifetime = 3d
Postfix und MySQL
Damit Postfix MySQL-Tabellen nutzen kann muss man folgende Dateien einrichten:
/etc/postfix/mysql_virtual_alias_maps.cf /etc/postfix/mysql_virtual_domains_maps.cf /etc/postfix/mysql_virtual_mailbox_limit_maps.cf /etc/postfix/mysql_virtual_mailbox_maps.cf /etc/postfix/mysql_virtual_alias_domain_maps.cf /etc/postfix/mysql_virtual_alias_domain_catchall_maps.cf /etc/postfix/mysql_virtual_alias_domain_mailbox_maps.cf
Diese mysql-Dateien im Verzeichnis /etc/postfix muss man anpassen an die eigenen Datenbankeinstellungen. Muster dazu finden sich in der Datei /usr/share/doc/postfixadmin/DOCUMENTS/POSTFIX_CONF.txt.gz. Im Prinzip wird Postfix hier mitgeteilt, wie die Datenbanktabellen abgefragt werden. Benutzername und Passwort müssen hier an die eigenen Einstellungen angepasst werden.
Für die Dateien kenne ich jeweisl zwei unterschiedliche Formulierungen, hier am Beispiel der mysql_virtual_domains_maps.cf
SuSE-Version
user = postfix password = password hosts = localhost #hosts = 127.0.0.1 dbname = postfix table = domain select_field = domain where_field = domain additional_conditions = and backupmx = '0' and active = '1'
Übliche Version.
user = postfix password = password hosts = localhost dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
Man sieht, dass die SuSE-Version etwas erweitert wurde. Bei Ubuntu findet man jeweils die übliche Form.
mysql_virtual_alias_maps.cf
user = postfix password = password hosts = localhost dbname = postfix query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
mysql_virtual_domains_maps.cf
user = postfix password = password hosts = localhost dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
mysql_virtual_mailbox_limit_maps.cf
user = postfix password = password hosts = localhost dbname = postfix query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
mysql_virtual_mailbox_maps.cf
user = postfix password = password hosts = localhost dbname = postfix query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
mysql_virtual_alias_domain_maps.cf
user = postfix
password = password
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
mysql_virtual_alias_domain_catchall_maps.cf:
# handles catch-all settings of target-domain
user = postfix
password = password
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
mysql_virtual_alias_domain_mailbox_maps.cf:
user = postfix
password = password
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
Firewall anpassen
ufw allow Postfix ufw allow "Postfix SMTPS" ufw allow "Postfix Submission" ufw allow "Dovecot IMAP" ufw allow "Dovecot Secure IMAP" ufw allow "Dovecot POP3" ufw allow "Dovecot Secure POP3"
master.cf kontrollieren
Hier ist erst einmal nur eine Einstellung wichtig, in Zeile 12 muss das Kommentarzeichen am Anfang entfernt sein:
smtp inet n - y - - smtpd
vsftpd
Da wir auf dem System nur virtuelle Nutzer haben, muss auch der FTP-Server auf die Benutzerdatenbank zugreifen können. Dazu dienen die folgenden Konfigurationsschritte:
Bei 18.04 scheint das Paket libpam-mysql in Ordnung zu sein. Die Installation von vsftpd ist dadurch relativ einfach:
apt install libpam-mysql
direkt installieren.
Nun müssen noch am Anfang der Datei /etc/pam.d/vsftpd zwei Zeilen ergänzt werden:
auth sufficient pam_mysql.so user=postfix passwd=asswd host=localhost db=postfix table=mailbox usercolumn=username passwdcolumn=password crypt=1 where=active="1" account sufficient pam_mysql.so user=postfix passwd=asswd host=localhost db=postfix table=mailbox usercolumn=username passwdcolumn=password crypt=1 where=active="1" # Standard behaviour for ftpd(8). auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed ...
Mit den beiden Zeilen wird dem Pam-System (bzw. dem Modul pam_mysql) mitgeteilt, dass es auf die MySQL-Datenbank zugreifen soll und wo es die notwendigen Daten findet. Statt der beiden langen Parameterlisten könnte man auch mit einem config_file arbeiten ( auth required pam_mysql.so config_file=/lib/security/pam_mysql.conf). Das hätte dann folgenden Aufbau:
users.host localhost users.database postix users.db_user postfix users.db_passwd asswd users.table mailbox users.user_column username users.password_column password users.password_crypt 1 users.where_clause active="1"
Nun habe ich in der Datei /etc/vsftpd.conf noch ein paar Änderungen vorgenommen. Hier eine Liste aller aktiven Einstellungen in alphabetischer Reihenfolge:
allow_writeable_chroot=YES anon_world_readable_only=YES anonymous_enable=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list chroot_local_user=YES connect_from_port_20=YES dirmessage_enable=YES dual_log_enable=YES guest_enable=YES guest_username=ftp listen=YES local_enable=YES log_ftp_protocol=YES nopriv_user=ftpsecure pam_service_name=vsftpd pasv_max_port=30100 pasv_min_port=30000 rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key secure_chroot_dir=/var/run/vsftpd/empty setproctitle_enable=YES ssl_enable=NO use_localtime=YES user_config_dir=/etc/vsftpd/ vsftpd_log_file=/var/log/vsftpd.log write_enable=YES xferlog_enable=YES xferlog_file=/var/log/xferlog xferlog_std_format=YES
Der hier benutzte unterprevilegierte User ftpsecure muss noch angelegt werden:
adduser --system --home /var/run/vsftpd/empty --no-create-home --disabled-login ftpsecure
Nun muss noch für jeden Benutzer, der FTP nutzen können soll, eine Datei in /etc/vsftpd erstellt werden. Der Name der Datei ist der Benutzername, hier also die Mailadresse.
local_root=/var/www/vhosts/<verzeichnis>/httpdocs anon_umask=022 anonymous_enable=YES anon_world_readable_only=NO anon_upload_enable=YES anon_umask=022 anon_mkdir_write_enable=YES anon_other_write_enable=YES guest_username=www-data connect_from_port_20=YES
Automatische Updates
Auch eine Server-Distribution muss gelegentlich aktualisiert werden. Dazu dient das Paket unattended-upgrades, das zuerst einmal installiert werden muss.
apt-get install unattended-upgrades
Es gibt dann ein paar Konfigurationdateien, die angepasst werden müssen/können. /etc/apt/apt.conf.d/50unattended-upgrades
// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
// Extended Security Maintenance; doesn't necessarily exist for
// every release and this system may not have it installed, but if
// available, the policy for updates is such that unattended-upgrades
// should also install from here by default.
"${distro_id}ESM:${distro_codename}";
"${distro_id}:${distro_codename}-updates";
// "${distro_id}:${distro_codename}-proposed";
// "${distro_id}:${distro_codename}-backports";
};
// List of packages to not update (regexp are supported)
Unattended-Upgrade::Package-Blacklist {
// "vim";
// "libc6";
// "libc6-dev";
// "libc6-i686";
};
// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
// dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
//Unattended-Upgrade::AutoFixInterruptedDpkg "false";
// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGUSR1. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "true";
// Install all unattended-upgrades when the machine is shuting down
// instead of doing it in the background while the machine is running
// This will (obviously) make shutdown slower
Unattended-Upgrade::InstallOnShutdown "false";
// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "user@example.com"
Unattended-Upgrade::Mail "root";
...
In dem oberen Bereich legt man Fest, welche Art von Updates installiert werden. Ich habe zusätzlich "${distro_id}:${distro_codename}-updates" aktiviert. Außerdem lasse ich mir per Mail berichten.
Dann sollte man noch die Datei /etc/apt/apt.conf.d/10periodic anlegen:
APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Download-Upgradeable-Packages "1"; APT::Periodic::AutocleanInterval "7"; APT::Periodic::Unattended-Upgrade "1";
Ausführlichere Informationen finden sich unter https://www.techgrube.de/tutorials/automatische-updates-auf-ubuntu-server-nutzen und http://kilobyte.bplaced.net/ubuntu-automatische-aktualisierung-aktivieren-ein-appell/
Alle Dienste
Der Aufruf von
service --status-all
liefert die folgende Ausgabe (insgesamt 61 Zeilen)
[ + ] amavis [ + ] amavis-mc [ + ] amavisd-snmp-subagent [ + ] apache-htcacheclean [ + ] apache2 [ + ] apparmor [ - ] bootmisc.sh [ - ] checkfs.sh [ - ] checkroot-bootclean.sh [ - ] checkroot.sh [ + ] clamav-daemon [ + ] clamav-freshclam [ - ] console-setup [ + ] cron [ + ] dbus [ + ] dovecot [ + ] fail2ban [ + ] grub-common [ - ] hostname.sh [ - ] hwclock.sh [ + ] irqbalance [ + ] iscsid [ + ] keyboard-setup [ - ] killprocs [ + ] kmod [ + ] mailman [ + ] mdadm [ - ] mdadm-waitidle [ - ] mountall-bootclean.sh [ - ] mountall.sh [ - ] mountdevsubfs.sh [ - ] mountkernfs.sh [ - ] mountnfs-bootclean.sh [ - ] mountnfs.sh [ + ] mysql [ - ] networking [ + ] ntp [ + ] ondemand [ + ] open-iscsi [ - ] plymouth [ - ] plymouth-log [ + ] postfix [ + ] procps [ + ] rc.local [ + ] resolvconf [ - ] rsync [ + ] rsyslog [ - ] sendsigs [ + ] smartmontools [ + ] spamass-milter [ + ] spamassassin [ + ] ssh [ + ] udev [ + ] ufw [ - ] umountfs [ - ] umountnfs.sh [ - ] umountroot [ + ] unattended-upgrades [ + ] urandom [ - ] uuidd [ + ] vsftpd [ - ] x11-common
MySQL
In aktuellen Datenbank-Versionen hat der Benutzer root keinen Zugriff mittels Passwort und kann daher z.B. auch nicht per phpmyadmin arbeiten. Der folgende MySQL-Befehl zeigt die Einstellung
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user; +---------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +---------------------+-------------------------------------------+-----------------------+-----------+ | root | | auth_socket | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | ...
Ändern lässt sich diese Einstellung mittels:
use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; flush privileges;
Dann ergibt sich:
mysql> select user,authentication_string,plugin,host FROM mysql.user; +---------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +---------------------+-------------------------------------------+-----------------------+-----------+ | root | *A9172BC315E0BF4D14D201C4CD16374ED187B2B3 | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
Das Passwort für MySQL lässt sich nicht mehr mit den altbekannten Kommandos setzen, weil das Passwort nicht mehr im Feld password, sondern im Feld authentication_string zu finden ist:
use mysql;
UPDATE user SET authentication_string= password('password') WHERE User = 'root';
flush privileges;
und
https://www.digitalocean.com/community/tutorials/so-installieren-sie-mysql-auf-ubuntu-18-04-de
Nachdem das Passwort gesetzt ist, kann sich der Benutzer root auch per phpmyadmin anmelden.
MySQL im Zusammenspiel mit phpmyadmin
Eine etwas einfachere Lösung das Passwort-Problem zu lösen gibt es, wenn mit phpmyadmin gearbeitet wird. In der Datei /etc/mysql/debian.cnf sind die Zugangsdaten für einen bei der Installation angelegten User zu finden:
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = BmhrjzFR0D0521NX socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = BmhrjzFR01D021NX socket = /var/run/mysqld/mysqld.sock
Mit dem hier befindlichen Benutzer und dem hier befindlichen zufällig generiertem Passwort kann man per phpmyadmin auf die Datenbank zugreifen. Hier kann man dann bequem einen Benutzer mit allen gewünschten Rechten anlegen.