Home / Linux Admin /
Note that this is fairly specific for Debian 9. The clamav component also appears to require that you run this on a server with at least 2 gigs of memory. (I had a 1 gig vm have clam crash after a few hours, requiring a reboot to get back up and running again. 2 gigs seems stable, but more is definitely better)
Confirm hostname is correct:
nano /etc/hosts
It should look something like this, if the server name is controlpanel and the domain name is yourdomain.com:
127.0.0.1 localhost
[localMachineIP - noBrackets] controlpanel.yourdomain.com controlpanel
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
nano /etc/hostname
controlpanel from the above example)hostnamehostname -fdpkg-reconfigure dash
Make sure you have contrib non-free tagged onto your current sources:
should look like (with server being whatever your current server is)
# deb http://server/debian/ stretch main
deb http://server/debian/ stretch main contrib non-free
deb-src http://server/debian/ stretch main contrib non-free
deb http://security.debian.org/debian-security stretch/updates main contrib non-free
deb-src http://security.debian.org/debian-security stretch/updates main contrib non-free
apt update && apt upgrade -yInstall the following packages (apt install ... ... yes it's a doozy)
ssh openssh-server nano dnsutils ntp postfix postfix-mysql postfix-doc mariadb-client mariadb-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve dovecot-lmtpd sudo amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl libdbd-mysql-perl postgrey git lua5.1 liblua5.1-0-dev lua-filesystem libidn11-dev libssl-dev lua-zlib lua-expat lua-event lua-bitop lua-socket lua-sec luarocks luarocks apache2 apache2-doc apache2-utils libapache2-mod-php libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick libruby libapache2-mod-python memcached php-memcache php-imagick php-gettext memcached libapache2-mod-passenger php-soap php php-common php-gd php-mysql php-imap phpmyadmin php-cli php-cgi php-mcrypt php-curl php-pspell php-recode php-sqlite3 php-tidy php-xmlrpc php-xsl php-intl php-zip php-mbstring certbot php-fpm php-opcache php-apcu pure-ftpd-common pure-ftpd-mysql quota quotatool bind9 dnsutils haveged webalizer awstats geoip-database libclass-dbi-mysql-perl libtimedate-perl build-essential autoconf automake libtool flex bison debhelper binutils fail2ban roundcube roundcube-core roundcube-mysql roundcube-pluginshostname.domain.tldcontrolpanel.yourdomain.com in the earlier exampleConfigure and secure MariaDB (MariaDB is a drop in replacement for MySQL):
mysql_secure_installation
nano /etc/mysql/mariadb.conf.d/50-server.cnf
should look like (NO_ENGINE_SUBSTITUTION line is new):
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
sql-mode="NO_ENGINE_SUBSTITUTION"
[...]
echo "update mysql.user set plugin = 'mysql_native_password' where user='root';" | mysql -u root
nano /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = root
password = [rootSQLpasswordNobrackets]
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = root
password = [rootSQLpasswordNobrackets]
socket = /var/run/mysqld/mysqld.sock
basedir = /usrservice mysql restartnetstat -tulpn and look for an entry for mysqld LISTENING on port 3306service spamassassin stopsystemctl disable spamassassinConfigure Postfix:
nano /etc/postfix/master.cf
should look like:
[...]
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
smtps inet n - - - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
[...]
apt install mailman
newlist mailman
nano /etc/aliases
newaliasesservice postfix restartln -s /etc/mailman/apache.conf /etc/apache2/conf-enabled/mailman.conf
service mailman startConfigure Metronome for Jabber (optional)
echo "deb http://packages.prosody.im/debian stretch main" > /etc/apt/sources.list.d/metronome.listwget http://prosody.im/files/prosody-debian-packages.key -O - | sudo apt-key add -luarocks install lpcadduser --no-create-home --disabled-login --gecos 'Metronome' metronomecd /opt; git clone https://github.com/maranda/metronome.git metronomecd ./metronome; ./configure --ostype=debian --prefix=/usrmakemake installconfigure Roundcube
nano /etc/roundcube/config.inc.php
make sure these values are set:
$config['default_host'] = 'localhost';
$config['smtp_server'] = 'localhost';
nano /etc/apache2/conf-enabled/roundcube.conf
Alias /webmail /var/lib/roundcubeConfigure Apache
a2enmod suexec rewrite ssl actions include dav_fs dav auth_digest cgi headers actions proxy_fcgi aliasworkaround HTTPOXY vulnerability
nano /etc/apache2/conf-available/httpoxy.conf
contents should be:
<IfModule mod_headers.c>
RequestHeader unset Proxy early
</IfModule>
a2enconf httpoxyservice apache2 restartln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.confConfigure PureFTPd
nano /etc/default/pure-ftpd-common
should look like:
[...]
STANDALONE_OR_INETD=standalone
[...]
VIRTUALCHROOT=true
[...]
echo 1 > /etc/pure-ftpd/conf/TLSecho "40000 45000" > /etc/pure-ftpd/conf/PassivePortRange
/etc/init.d/pure-ftpd-mysql restartConfigure quota
nano /etc/fstab
,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 to the partition with mount point of /should look vaguely like:
/dev/sda1 / ext4 errors=remount-ro,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 0 1
mount -o remount /quotacheck -avugmquotaon -avugnano /etc/cron.d/awstats#cd /tmpwget http://olivier.sessink.nl/jailkit/jailkit-2.19.tar.gztar xvfz jailkit-2.19.tar.gzcd jailkit-2.19echo 5 > debian/compat./debian/rules binarycd ..dpkg -i jailkit_2.19-1_*.debrm -rf jailkit-2.19*Configure fail2ban
nano /etc/fail2ban/jail.local
insert following contents:
[pure-ftpd]
enabled = true
port = ftp
filter = pure-ftpd
logpath = /var/log/syslog
maxretry = 3
[dovecot]
enabled = true
filter = dovecot
logpath = /var/log/mail.log
maxretry = 5
[postfix-sasl]
enabled = true
port = smtp
filter = postfix-sasl
logpath = /var/log/mail.log
maxretry = 3
service fail2ban restartRun ISPConfig setup
cd /tmpwget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gztar -zxvf ISPConfig-3-stable.tar.gzcd ispconfig3_install/install/php -q install.php
ControlPanel SSL (This section assumes you're server is properly networked at this point, can be accessed from the internet, and dns is configured) - credit for this section
ispconfig_update.shcd /usr/local/ispconfig/interface/ssl/mkdir $(date +"%y%m%d%H%M%S").bakmv ispserver.* [the new folder that was just created no brackets]ln -s /etc/letsencrypt/live/$(hostname -f)/fullchain.pem ispserver.crtln -s /etc/letsencrypt/live/$(hostname -f)/privkey.pem ispserver.keycat ispserver.{key,crt} > ispserver.pemchmod 600 ispserver.pemcd /etc/postfix/mv smtpd.cert smtpd.cert-$(date +"%y%m%d%H%M%S").bakmv smtpd.key smtpd.key-$(date +"%y%m%d%H%M%S").bakln -s /usr/local/ispconfig/interface/ssl/ispserver.crt smtpd.certln -s /usr/local/ispconfig/interface/ssl/ispserver.key smtpd.keyservice postfix restartservice dovecot restartConfigure dovecot:
nano /etc/dovecot/dovecot.confconfirm the following exists in the file:
[...]
ssl_cert = </etc/postfix/smtpd.cert
ssl_key = </etc/postfix/smtpd.key
[...]
service dovecot restart
cd /etc/ssl/private/mv pure-ftpd.pem pure-ftpd.pem-$(date +"%y%m%d%H%M%S").bakln -s /usr/local/ispconfig/interface/ssl/ispserver.pem pure-ftpd.pemchmod 600 pure-ftpd.pemservice pure-ftpd-mysql restartAutomate the updates:
apt install -y incronnano /etc/init.d/le_ispc_pem.shcopy/paste the following contents:
#!/bin/sh
### BEGIN INIT INFO
# Provides: LE ISPSERVER.PEM AUTO UPDATER
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: LE ISPSERVER.PEM AUTO UPDATER
# Description: Update ispserver.pem automatically after ISPC LE SSL certs are renewed.
### END INIT INFO
cd /usr/local/ispconfig/interface/ssl/
mv ispserver.pem ispserver.pem-$(date +"%y%m%d%H%M%S").bak
cat ispserver.{key,crt} > ispserver.pem
chmod 600 ispserver.pem
chmod 600 /etc/ssl/private/pure-ftpd.pem
service pure-ftpd-mysql restart
service postfix restart
service dovecot restart
service apache2 restart
chmod +x /etc/init.d/le_ispc_pem.shecho "root" >> /etc/incron.allowincrontab -e/etc/letsencrypt/archive/$(hostname -f)/ IN_MODIFY ./etc/init.d/le_ispc_pem.shservice apache2 restart or just reboot your server212225538011014344395399399540000:45000/tcp8080 is default)Please give credit to this walkthrough which much of this is based off of.
this document last modified: March 27 2018 00:10
Home / Linux Admin /