Note that it's ultimately the responsibility of the server admin to ensure his system is secure. These are some basic security tips that can be done to help protect your system. This is not an end-all guide for server security, admins must be diligent, but rather some suggestions for a start to securing your server.
/tmppartition with the noexec,nosuid options, and mount the
/homepartition with the nosuid option. This is done in your
/etc/fstaband requires those paths to exist as partitions, and not just as subdirectories of
/. If you're unsure, type:
to get a listing of your partitions and their current mounting options. Use Google for more information on these mounting options.
Be very careful when editing your
/etc/fstab, as any errors could prevent your system from starting up. Note that you must not have "nosuid,noexec" for
/usr, as those partitions have suid binaries normally (su, passwd, etc).
Note that some PHP scripts do legitimately require these functions to operate, so if your scripts don't run after enabling this function, edit your php.ini to remove the required functions from the list, and restart Apache. To add the disable_functions with CustomBuild, type the following then restart Apache:
cd /usr/local/directadmin/custombuild ./build update ./build secure_php
Use following guide to update manually or automate: </custombuild/upgrading-services>.
Ensure clean_old_webapps is set to yes in
options.conf file . This removes all scripts from
/var/www/html, after updating you to a new version.
If you're running PHP in mod_php mode, then enabling both PHP SafeMode and open_basedir is wise. Safemode is an internal form of disable_functions which also does a bit more checking. See the documentation on Safemode for more info on this. Open_basedir, which is enabled by default, tells PHP to not allow scripts to access files outside of the set list of paths.
To control SafeMode and Open_Basedir on your PHP CLI system (default), go to Admin Level -> Php Safemode Config .
Start using PHP-FPM as your PHP engine. More information here.
If you don't plan on doing any remote access to MySQL, then setting up mysqld to only listen on 127.0.0.1 would be a good idea. Note that you'll have to keep this in mind if your users start asking you why they can't connect to MySQL from a remote location.
To set MySQL to only bind to 127.0.0.1, add the following to the [mysqld] section of your /etc/my.cnf, then restart mysqld:
bind-address = 127.0.0.1
Start using a firewall. Many people use CSF and we recommend so.
Setup your named.conf to not allow recursion. This should be done by default now, but check anyway with this guide.
Prevent Users from using weak passwords by enabling difficult password enforcementopen in new window.
Prevent Users from creating subdomains belonging to other Users with this optionopen in new window.
If you're using DirectAdmin with SSL, it's a good idea to force all SSL connections to use TLS instead of other older SSL protocols.
Change the default SSH port from 22 to a more obscure value via
Brute Force Login Attempts are more common, so it's best not to have direct SSH logins for common accounts like root or admin. Generally, it's safe to use a hidden "su" user first, then login to root or other accounts once connected. Disable any accounts (root, admin, etc) that don't need direct access by editing the /etc/ssh/sshd_config. Always test changes before logging out else you may lock yourself out of the box.
Also, DirectAdmin has a Brute Force attack detection system for services, as well as an IP blocker for DA itself.
Force email logins to use a secure connection: http://www.directadmin.com/forum/showthread.php?t=43500open in new window
Disable UserDir Apache ability ( http://126.96.36.199/~username access):
cd /usr/local/directadmin/custombuild ./build set userdir_access no ./build rewrite_confs
Consider using CloudLinux with CageFS: https://www.cloudlinux.com/cagefsopen in new window
Consider enabling a jail-system based on Linux namespaces by compiling it from CustomBuild:
cd /usr/local/directadmin/custombuild ./build update ./build bubblewrap
Note: bubblewrap will not work on LXC/OpenVZ and CloudLinux systems.
If you're trying to become PCI compliant, one common check they do is to see if any of your SSL connections are using SSLv3.
You can fill in these options to generate the desired command:
If you want to check your own setup first to ensure it will pass this check, you can use the command:
openssl s_client -port "2222" -host "127.0.0.1" "-ssl3"
where you'll replace the items with the respective values you're trying to test.
In the above example, we're checking DA on port 2222 locally (127.0.0.1), but a remote check to anywhere else, with any port can be used.
If SSLv3 is not allowed in that connection (which is good), then you'll see about 3 to 7 lines of output, and the last line will show something like:
140506571089736:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1257:SSL alert number 40 140506571089736:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:596:
Basically, it will throw some kind of error.
If** the connection worked** (which is bad if testing for -ssl3), then you'll see a full page of output, including all certificate information, as well as the certificate itself.
Some services, like Exim, use TLS for their SSL connection. In that case, you'd use -tls1, -tls1_1, or -tls1_2 to test to for various TLS versions, instead of -ssl3 .
To set ciphers for the services, see this guide.
If you need to generate an MD5 hash from the command line, the openssl binary can do this very easily.
openssl passwd -1 password
where password would be replaced with the password you'd like to encrypt.
There are many scenarios where you'd not want a User or Users to execute a specific file. For example, wget or perl might be binaries that you don't want Users to run.
In this example, we'll discuss how to use group permissions to prevent a group of Users from executing the file:
Create the group like so:
chgrp "noperl" "/usr/bin/perl" chmod 705 "/usr/bin/perl"
where using the 705 permissions, the 0 portion specifies that the group on this file cannot do anything on it (can't read it, can't write to it, and cannot execute it).
usermod -a -G "noperl" apache usermod -a -G "noperl" fred usermod -a -G "noperl" george
where apache, fred, and george cannot run /usr/bin/perl.
This guide can be applied to other binaries as needed, but make sure that you don't block any Users which actually need to use the given binary.
/usr/local/directadmin/scripts/custom/user_create_post.shand add the code:
#!/bin/sh /usr/sbin/usermod -a -G noperl $username 2>&1 RET=$? exit $RET
And make it executable:
chmod 755 /usr/local/directadmin/scripts/custom/user_create_post.sh
Part of the design of DirectAdmin is to automate root level tasks, while not allowing Users to affect things that they should not.
There might be some cases where you want to allow Users to run something as root, but without giving them root access.
In this example, we'll say we want to let User restart proftpd on command.
The action done can really be anything, but this outlines the basics of how it works. Obviously, you'd need to pick a command that you don't mind them running, possibly more often than you're expecting.
We'll accomplish this by having a root cronjob scanning for files that the User can create, e.g.,
/root/check_proftpd_restart.shand add the code:
#!/bin/sh COUNT=`ls "/home/*/restart_proftpd" 2>/dev/null | grep -c "restart_proftpd"` if [ "$COUNT" -gt 0 ]; then echo "Restarting proftpd, triggered by "; ls "/home/*/restart_proftpd" echo "action=proftpd&value=restart" >> /usr/local/directadmin/data/task.queue rm -f "/home/*/restart_proftpd" fi exit 0;
and make it executable:
chmod 755 /root/check_proftpd_restart.sh
echo '* * * * * root /root/check_proftpd_restart.sh' > /etc/cron.d/check_proftpd chmod 600 /etc/cron.d/check_proftpd service crond restart
It might take up to 2 full minutes for proftpd to get restarted, as the dataskq would need to find the task.queue in the same manner. If this is too long, the echo task.queue command could be replaced with a more direct
service proftpd restart command, just be careful of possible piping issues.