{"id":226,"date":"2013-06-05T12:15:37","date_gmt":"2013-06-05T12:15:37","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=226"},"modified":"2013-06-05T12:15:37","modified_gmt":"2013-06-05T12:15:37","slug":"how-to-secure-and-optimize-your-vps","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/06\/05\/how-to-secure-and-optimize-your-vps\/","title":{"rendered":"How To Secure and Optimize Your VPS"},"content":{"rendered":"<p><b><span style=\"color: #8b0000;\">SECURING CPANEL &#8211; WHM &#8211; AND ROOT on a VPS<\/span><\/b><\/p>\n<p>This will help but as mentioned in previous posts, with a VPS you do not have access to your kernal. That is good in some ways, because if you don&#8217;t have access to it, neither to hackers or spammers (which limits what they can do). Its bad in ways, because you lose control and if you secure your box as much as possible, you are still at risk because you cannot control your kernal.<\/p>\n<p>At any rate, here are some helpful hints\u00a0<img decoding=\"async\" title=\"Smilie\" alt=\"\" src=\"https:\/\/www.webhostingtalk.com\/images\/wht_smilies\/smile.gif\" border=\"0\" \/><\/p>\n<p>=========================================<br \/>\n<b><span style=\"color: #8b0000;\">Checking for formmail<\/span><\/b><br \/>\n=========================================<\/p>\n<p>Form mail is used by hackers to send out spam email, by relay and injection methods. If you are using matts script or a version of it, you may be in jeopardy.<\/p>\n<p>Command to find pesky form mails:<br \/>\nfind \/ -name &#8220;[Ff]orm[mM]ai*&#8221;<\/p>\n<p>CGIemail is also a security risk:<br \/>\nfind \/ -name &#8220;[Cc]giemai*&#8221;<\/p>\n<p>Command to disable form mails:<br \/>\nchmod a-rwx \/path\/to\/filename<br \/>\n(a-rwx translates to all types, no read, write or execute permissions).<\/p>\n<p>(this disables all form mail)<\/p>\n<p>If a client or someone on your vps installs form mail, you will have to let them know you are disabling their script and give them an alternative.<\/p>\n<p>=========================================<br \/>\n<span style=\"color: #8b0000;\"><b>Root kit checker &#8211;\u00a0<\/b><\/span><a href=\"http:\/\/www.chkrootkit.org\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color: #8b0000;\"><b>http:\/\/www.chkrootkit.org\/<\/b><\/span><\/a><br \/>\n=========================================<\/p>\n<p>Check for root kits and even set a root kit on a cron job. This will show you if anyone has compromised your root. Always update chrootkit to get the latest root kit checker. Hackers and spammers will try to find insecure upload forms on your box and then with injection methods, try to upload the root kit on your server. If he can run it, it will modify *alot* of files, possibly causing you to have to reinstall.<\/p>\n<p>To install chrootkit, SSH into server and login as root.<br \/>\nAt command prompt type:<\/p>\n<p>cd \/root\/<br \/>\nwget\u00a0<a href=\"ftp:\/\/ftp.pangeia.com.br\/pub\/seg\/pac\/chkrootkit.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\">ftp:\/\/ftp.pangeia.com.br\/pub\/seg\/pac\/chkrootkit.tar.gz<\/a><br \/>\ntar xvzf chkrootkit.tar.gz<br \/>\ncd chkrootkit-0.44<br \/>\nmake sense<\/p>\n<p>To run chkrootkit<\/p>\n<p>At command prompt type:<br \/>\n\/root\/chkrootkit-0.44\/chkrootkit<\/p>\n<p>Make sure you run it on a regular basis, perhaps including it in a cron job.<\/p>\n<p>Execution<\/p>\n<p>I use these three commands the most.<br \/>\n.\/chkrootkit<br \/>\n.\/chkrootkit -q<br \/>\n.\/chkrootkit -x | more<\/p>\n<p>=========================================<br \/>\n<b><span style=\"color: #8b0000;\">Install a root breach DETECTOR and EMAIL WARNING\u00a0<\/span><\/b><br \/>\n=========================================<\/p>\n<p>If someone does happen to get root, be warned quickly by installing a detector and warning at your box. You will at least get the hackers\/spammers ip address and be warned someone is in there.<\/p>\n<p>Server e-mail everytime someone logs in as root<\/p>\n<p>To have the server e-mail you everytime someone logs in as root, SSH into server and login as root.<\/p>\n<p>At command prompt type:<br \/>\npico .bash_profile<\/p>\n<p>Scroll down to the end of the file and add the following line:<\/p>\n<p>echo &#8216;ALERT &#8211; Root Shell Access on:&#8217; `date` `who` | mail -s &#8220;Alert: Root Access from `who | awk &#8216;{print $6}&#8217;`&#8221;\u00a0<a href=\"mailto:your@email.com\">your@email.com<\/a><\/p>\n<p>Save and exit.<\/p>\n<p>Set an SSH Legal Message<\/p>\n<p>To an SSH legal message, SSH into server and login as root.<\/p>\n<p>At command prompt type:<br \/>\npico \/etc\/motd<\/p>\n<p>Enter your message, save and exit.<br \/>\nNote: I use the following message&#8230;<\/p>\n<p>ALERT! You are entering a secured area! Your IP and login information<br \/>\nhave been recorded. System administration has been notified.<br \/>\nThis system is restricted to authorized access only. All activities on<br \/>\nthis system are recorded and logged. Unauthorized access will be fully<br \/>\ninvestigated and reported to the appropriate law enforcement agencies.<\/p>\n<p>=========================================<br \/>\n<span style=\"color: #8b0000;\"><b>Web Host manager and CPANEL mods.<\/b><\/span><br \/>\n=========================================<\/p>\n<p>These are items inside of WHM\/Cpanel that should be changed to secure your server.<\/p>\n<p>Goto Server Setup =&gt;&gt; Tweak Settings<br \/>\nCheck the following items&#8230;<\/p>\n<p>Under Domains<br \/>\nPrevent users from parking\/adding on common internet domains. (ie hotmail.com, aol.com)<\/p>\n<p>Under Mail<br \/>\nAttempt to prevent pop3 connection floods<br \/>\nDefault catch-all\/default address behavior for new accounts &#8211; blackhole<br \/>\n<b>(according to ELIX &#8211; set this to FAIL, which is what I am going to do to reduce server load)<\/b><\/p>\n<p>Under System<br \/>\nUse jailshell as the default shell for all new accounts and modified accounts<\/p>\n<p>Goto Server Setup =&gt;&gt; Tweak Security<br \/>\nEnable php open_basedir Protection<br \/>\nEnable mod_userdir Protection<br \/>\nDisabled Compilers for unprivileged users.<\/p>\n<p>Goto Server Setup =&gt;&gt; Manage Wheel Group Users<br \/>\nRemove all users except for root and your main account from the wheel group.<\/p>\n<p>Goto Server Setup =&gt;&gt; Shell Fork Bomb Protection<br \/>\nEnable Shell Fork Bomb\/Memory Protection<\/p>\n<p>When setting up Feature Limits for resellers in Resellers =&gt;&gt; Reseller Center, under Privileges always disable Allow Creation of Packages with Shell Access and enable Never allow creation of accounts with shell access; under Root Access disable All Features.<\/p>\n<p>Goto Service Configuration =&gt;&gt; FTP Configuration<br \/>\nDisable Anonymous FTP<\/p>\n<p>Goto Account Functions =&gt;&gt; Manage Shell Access<br \/>\nDisable Shell Access for all users (except yourself)<\/p>\n<p>Goto Mysql =&gt;&gt; MySQL Root Password<br \/>\nChange root password for MySQL<\/p>\n<p>Goto Security and run Quick Security Scan and Scan for Trojan Horses often. The following and similar items are not Trojans:<br \/>\n\/sbin\/depmod<br \/>\n\/sbin\/insmod<br \/>\n\/sbin\/insmod.static<br \/>\n\/sbin\/modinfo<br \/>\n\/sbin\/modprobe<br \/>\n\/sbin\/rmmod<\/p>\n<p>=========================================<br \/>\n<b><span style=\"color: #8b0000;\">More Security Measures\u00a0<\/span><\/b><br \/>\n=========================================<\/p>\n<p>These are measures that can be taken to secure your server, with SSH access.<\/p>\n<p>Update OS, Apache and CPanel to the latest stable versions.<br \/>\nThis can be done from WHM\/CPanel.<\/p>\n<p>Restrict SSH Access<br \/>\nTo restrict and secure SSH access, bind sshd to a single IP that is different than the main IP to the server, and on a different port than port 22.<\/p>\n<p>SSH into server and login as root.<br \/>\nNote: You can download Putty by Clicking Here (<a href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.chiark.greenend.org.uk\/~s&#8230;\/download.html<\/a>). It&#8217;s a clean running application that will not require installation on Windows-boxes.<\/p>\n<p>At command prompt type:<br \/>\npico \/etc\/ssh\/sshd_config<\/p>\n<p>Scroll down to the section of the file that looks like this:<br \/>\n#Port 22<br \/>\n#Protocol 2, 1<br \/>\n#ListenAddress 0.0.0.0<br \/>\n#ListenAddress ::<\/p>\n<p>Uncomment and change<br \/>\n#Port 22<br \/>\nto look like<br \/>\nPort 5678 (choose your own 4 to 5 digit port number (49151 is the highest port number AND do not use 5678\u00a0<img decoding=\"async\" title=\"Smilie\" alt=\"\" src=\"https:\/\/www.webhostingtalk.com\/images\/wht_smilies\/smile.gif\" border=\"0\" \/>\u00a0lol )<\/p>\n<p>Uncomment and change<br \/>\n#Protocol 2, 1<br \/>\nto look like<br \/>\nProtocol 2<\/p>\n<p>Uncomment and change<br \/>\n#ListenAddress 0.0.0.0<br \/>\nto look like<br \/>\nListenAddress 123.123.123.15 (use one of your own IP Addresses that has been assigned to your server)<\/p>\n<p>Note 1: If you would like to disable direct Root Login, scroll down until you find<br \/>\n#PermitRootLogin yes<br \/>\nand uncomment it and make it look like<br \/>\nPermitRootLogin no<\/p>\n<p>Save by pressing Ctrl o on your keyboard, and then exit by pressing Ctrl x on your keyboard.<\/p>\n<p>Note 2: You can also create a custome nameserver specifically for your new SSH IP address. Just create one called something like ssh.xyz.com or whatever. Be sure to add an A address to your zone file for the new nameserver.<\/p>\n<p>Now restart SSH<br \/>\nAt command prompt type:<br \/>\n\/etc\/rc.d\/init.d\/sshd restart<\/p>\n<p>Exit out of SSH, and then re-login to SSH using the new IP or nameserver, and the new port.<\/p>\n<p>Note: If you should have any problems, just Telnet into your server, fix the problem, then SSH in again. Telnet is a very unsecure protocol, so change your root password after you use it.<\/p>\n<p>After SSH has been redirected, disable telnet.<\/p>\n<p>Disable Telnet<br \/>\nTo disable telnet, SSH into server and login as root.<br \/>\nAt command prompt type: pico -w \/etc\/xinetd.d\/telnet<br \/>\nchange disable = no to disable = yes<br \/>\nSave and Exit<br \/>\nAt command prompt type: \/etc\/init.d\/xinetd restart<\/p>\n<p>Disable Shell Accounts<br \/>\nTo disable any shell accounts hosted on your server SSH into server and login as root.<br \/>\nAt command prompt type: locate shell.php<br \/>\nAlso check for:<br \/>\nlocate irc<br \/>\nlocate eggdrop<br \/>\nlocate bnc<br \/>\nlocate BNC<br \/>\nlocate ptlink<br \/>\nlocate BitchX<br \/>\nlocate guardservices<br \/>\nlocate psyBNC<br \/>\nlocate .rhosts<\/p>\n<p>Note: There will be several listings that will be OS\/CPanel related. Examples are<br \/>\n\/home\/cpapachebuild\/buildapache\/php-4.3.1\/ext\/ircg<br \/>\n\/usr\/local\/cpanel\/etc\/sym\/eggdrop.sym<br \/>\n\/usr\/local\/cpanel\/etc\/sym\/bnc.sym<br \/>\n\/usr\/local\/cpanel\/etc\/sym\/psyBNC.sym<br \/>\n\/usr\/local\/cpanel\/etc\/sym\/ptlink.sym<br \/>\n\/usr\/lib\/libncurses.so<br \/>\n\/usr\/lib\/libncurses.a<br \/>\netc.<\/p>\n<p>Disable identification output for Apache<\/p>\n<p>(do this to hide version numbers from potentional hackers)<\/p>\n<p>To disable the version output for proftp, SSH into server and login as root.<br \/>\nAt command prompt type: pico \/etc\/httpd\/conf\/httpd.conf<\/p>\n<p>Scroll (way) down and change the following line to<br \/>\nServerSignature Off<\/p>\n<p>Restart Apache<br \/>\nAt command prompt type: \/etc\/rc.d\/init.d\/httpd restart<\/p>\n<p>=========================================<br \/>\n<b><span style=\"color: #8b0000;\">Install BFD (Brute Force Detection &#8211; optional)<\/span><\/b><br \/>\n=========================================<\/p>\n<p>To install BFD, SSH into server and login as root.<\/p>\n<p>At command prompt type:<br \/>\ncd \/root\/<br \/>\nwget\u00a0<a href=\"http:\/\/www.rfxnetworks.com\/downloads\/bfd-current.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.rfxnetworks.com\/downloads\/bfd-current.tar.gz<\/a><br \/>\ntar -xvzf bfd-current.tar.gz<br \/>\ncd bfd-0.4<br \/>\n.\/install.sh<\/p>\n<p>After BFD has been installed, you need to edit the configuration file.<\/p>\n<p>At command prompt type:<br \/>\npico \/usr\/local\/bfd\/conf.bfd<\/p>\n<p>Under Enable brute force hack attempt alerts:<br \/>\nFind<br \/>\nALERT_USR=&#8221;0&#8243;<br \/>\nand change it to<br \/>\nALERT_USR=&#8221;1&#8243;<\/p>\n<p>Find<br \/>\nEMAIL_USR=&#8221;root&#8221;<br \/>\nand change it to<br \/>\nEMAIL_USR=&#8221;<a href=\"mailto:your@email.com\">your@email.com<\/a>&#8221;<\/p>\n<p>Save the changes then exit.<\/p>\n<p>To start BFD<\/p>\n<p>At command prompt type:<br \/>\n\/usr\/local\/sbin\/bfd -s<\/p>\n<p>Modify LogWatch<br \/>\nLogwatch is a customizable log analysis system. It parses through your system&#8217;s logs for a given period of time and creates a report analyzing areas that you specify, in as much detail as you require. Logwatch is already installed on most CPanel servers.<\/p>\n<p>To modify LogWatch, SSH into server and login as root.<\/p>\n<p>At command prompt type:<br \/>\npico -w \/etc\/log.d\/conf\/logwatch.conf<\/p>\n<p>Scroll down to<br \/>\nMailTo = root<br \/>\nand change to<br \/>\nMailto =\u00a0<a href=\"mailto:your@email.com\">your@email.com<\/a><br \/>\nNote: Set the e-mail address to an offsite account incase you get hacked.<\/p>\n<p>Now scroll down to<br \/>\nDetail = Low<br \/>\nChange that to Medium, or High&#8230;<br \/>\nDetail = 5 or Detail = 10<br \/>\nNote: High will give you more detailed logs with all actions.<\/p>\n<p>Save and exit.<\/p>\n<p>A number of suggestions to improve system security. Some of this is specific to CPanel, but much can be applied to most Linux systems.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nUse The Latest Software<br \/>\nKeep the OS and 3rd party software up to date. Always!<br \/>\nCPanel itself can be updated from the root WHM.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nChange Passwords<br \/>\nChange the root passwords at least once a month and try to make them hard to guess. Yes it&#8217;s a pain to have to keep remembering them, but it&#8217;s better than being hacked.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSet Up A More Secure SSH Environment As described here.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nDisable Telnet<br \/>\n1. Type: pico -w \/etc\/xinetd.d\/telnet<br \/>\n2. Change the disable = no line to disable = yes.<br \/>\n3. Hit CTRL+X press y and then enter to save the file.<br \/>\n4. Restart xinted with: \/etc\/rc.d\/init.d\/xinetd restart<br \/>\nAlso, add the following line to \/etc\/deny.hosts to flag Telnet access attempts as &#8217;emergency&#8217; messages.<\/p>\n<p>in.telnetd : ALL : severity emerg<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nDisable Unnecessary Ports (optional)<br \/>\nFirst backup the file that contains your list of ports with:<br \/>\ncp \/etc\/services \/etc\/services.original<br \/>\nNow configure \/etc\/services so that it only has the ports you need in it. This will match the ports enabled in your firewall.<br \/>\nOn a typical CPanel system it would look something like this:<br \/>\n&lt;?php<br \/>\ntcpmux 1\/tcp # TCP port service multiplexer<br \/>\necho 7\/tcp<br \/>\necho 7\/udp<br \/>\nftp-data 20\/tcp<br \/>\nftp 21\/tcp<br \/>\nssh 22\/tcp # SSH Remote Login Protocol<br \/>\nsmtp 25\/tcp mail<br \/>\ndomain 53\/tcp # name-domain server<br \/>\ndomain 53\/udp<br \/>\nhttp 80\/tcp www www-http # WorldWideWeb HTTP<br \/>\npop3 110\/tcp pop-3 # POP version 3<br \/>\nimap 143\/tcp imap2 # Interim Mail Access Proto v2<br \/>\nhttps 443\/tcp # MCom<br \/>\nsmtps 465\/tcp # SMTP over SSL (TLS)<br \/>\nsyslog 514\/udp<br \/>\nrndc 953\/tcp # rndc control sockets (BIND 9)<br \/>\nrndc 953\/udp # rndc control sockets (BIND 9)<br \/>\nimaps 993\/tcp # IMAP over SSL<br \/>\npop3s 995\/tcp # POP-3 over SSL<br \/>\ncpanel 2082\/tcp<br \/>\ncpanels 2083\/tcp<br \/>\nwhm 2086\/tcp<br \/>\nwhms 2087\/tcp<br \/>\nwebmail 2095\/tcp<br \/>\nwebmails 2096\/tcp<br \/>\nmysql 3306\/tcp # MySQL<br \/>\n?&gt;<br \/>\nAdditional ports are controlled by \/etc\/rpc. These aren&#8217;t generally needed, so get shot of that file with: mv \/etc\/rpc \/etc\/rpc-moved<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nWatch The Logs<br \/>\nInstall something like logwatch to keep an eye on your system logs. This will extract anything &#8216;interesting&#8217; from the logs and e-mail to you on a daily basis.<br \/>\nLogwatch can be found at:\u00a0<a href=\"http:\/\/www.logwatch.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.logwatch.org<\/a><br \/>\nInstall instructions here.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nAvoid CPanel Demo Mode<br \/>\nSwitch it off via WHM Account Functions =&gt; Disable or Enable Demo Mode.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nJail All Users<br \/>\nVia WHM Account Functions =&gt; Manage Shell Access =&gt; Jail All Users.<br \/>\nBetter still never allow shell access to anyone &#8211; no exceptions.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nImmediate Notification Of Specific Attackers<br \/>\nIf you need immediate notification of a specific attacker (TCPWrapped services only), add the following to \/etc\/hosts.deny<\/p>\n<p>ALL : nnn.nnn.nnn.nnn : spawn \/bin\/ &#8216;date&#8217; %c %d | mail -s&#8221;Access attempt by nnn.nnn.nnn.nnn on for hostname&#8221;\u00a0<a href=\"mailto:notify@mydomain.com\">notify@mydomain.com<\/a><br \/>\nReplacing nnn.nnn.nnn.nnn with the attacker&#8217;s IP address.<br \/>\nReplacing hostname with your hostname.<br \/>\nReplacing\u00a0<a href=\"mailto:notify@mydomain.com\">notify@mydomain.com<\/a>\u00a0with your e-mail address.<br \/>\nThis will deny access to the attacker and e-mail the sysadmin about the access attempt.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nCheck Open Ports<br \/>\nFrom time to time it&#8217;s worth checking which ports are open to the outside world. This can be done with:<br \/>\nnmap -sT -O localhost<br \/>\nIf nmap isn&#8217;t installed, it can be selected from root WHM&#8217;s Install an RPM option.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSet The MySQL Root Password<br \/>\nThis can be done in CPanel from the root WHM Server Setup -&gt; Set MySQL Root Password.<br \/>\nMake it different to your root password!<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nTweak Security (CPanel)<br \/>\nFrom the root WHM, Server Setup -&gt; Tweak Security, you will most likely want to enable:<br \/>\n&#8211; php open_basedir Tweak.<br \/>\n&#8211; SMTP tweak.<br \/>\nYou may want to enable:<br \/>\n&#8211; mod_userdir Tweak. But that will disable domain preview.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nUse SuExec (CPanel)<br \/>\nFrom root WHM, Server Setup -&gt; Enable\/Disable SuExec. This is CPanel&#8217;s decription of what it does:<br \/>\n&#8220;suexec allows cgi scripts to run with the user&#8217;s id. It will also make it easier to track which user has sent out an email. If suexec is not enabled, all cgi scripts will run as nobody. &#8221;<br \/>\nEven if you don&#8217;t use phpsuexec (which often causes more problems), SuExec should be considered.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nUse PHPSuExec (CPanel)<br \/>\nThis needs to built into Apache (Software -&gt; Update Apache from the root WHM) and does the same as SuExec but for PHP scripts.<br \/>\nWisth PHPSuExec enabled, you users will have to make sure that all their PHP files have permissions no greater than 0755 and that their htaccess files contain no PHP directives.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nDisable Compilers<br \/>\nThis will prevent hackers from compiling worms, root kits and the like on your machine.<br \/>\nTo disable them, do the following:<\/p>\n<p>chmod 000 \/usr\/bin\/perlcc<br \/>\nchmod 000 \/usr\/bin\/byacc<br \/>\nchmod 000 \/usr\/bin\/yacc<br \/>\nchmod 000 \/usr\/bin\/bcc<br \/>\nchmod 000 \/usr\/bin\/kgcc<br \/>\nchmod 000 \/usr\/bin\/cc<br \/>\nchmod 000 \/usr\/bin\/gcc<br \/>\nchmod 000 \/usr\/bin\/i386*cc<br \/>\nchmod 000 \/usr\/bin\/*c++<br \/>\nchmod 000 \/usr\/bin\/*g++<br \/>\nchmod 000 \/usr\/lib\/bcc \/usr\/lib\/bcc\/bcc-cc1<br \/>\nchmod 000 \/usr\/i386-glibc21-linux\/lib\/gcc-lib\/i386-redhat-linux\/2.96\/cc1<\/p>\n<p>You will need to enable them again when you need to perform system updates. To do this, run:<\/p>\n<p>chmod 755 \/usr\/bin\/perlcc<br \/>\nchmod 755 \/usr\/bin\/byacc<br \/>\nchmod 755 \/usr\/bin\/yacc<br \/>\nchmod 755 \/usr\/bin\/bcc<br \/>\nchmod 755 \/usr\/bin\/kgcc<br \/>\nchmod 755 \/usr\/bin\/cc<br \/>\nchmod 755 \/usr\/bin\/gcc<br \/>\nchmod 755 \/usr\/bin\/i386*cc<br \/>\nchmod 755 \/usr\/bin\/*c++<br \/>\nchmod 755 \/usr\/bin\/*g++<br \/>\nchmod 755 \/usr\/lib\/bcc \/usr\/lib\/bcc\/bcc-cc1<br \/>\nchmod 755 \/usr\/i386-glibc21-linux\/lib\/gcc-lib\/i386-redhat-linux\/2.96\/cc1<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nObfuscate The Apache Version Number<br \/>\n1. Type: pico \/etc\/httpd\/conf\/httpd.conf<br \/>\n2. Change the line that begins ServerSignature to:<\/p>\n<p>ServerSignature Off<\/p>\n<p>3. Add a line underneath that which reads:<\/p>\n<p>ServerTokens ProductOnly<\/p>\n<p>4. Hit CTRL+X, they y, the enter to save the file.<br \/>\n5. Restart Apache with: \/etc\/rc.d\/init.d\/httpd restart<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>COMMON COMMANDS I USE<br \/>\nSystem Information<br \/>\nwho<br \/>\nList the users logged in on the machine. &#8212;<\/p>\n<p>rwho -a<br \/>\nList all users logged in on your network. The rwho service must be enabled for this command to work.<\/p>\n<p>finger user_name<br \/>\nSystem info about a user. Try: finger root last. This lists the users last logged-in on your system.<\/p>\n<p>history | more<br \/>\nShow the last (1000 or so) commands executed from the command line on the current account. The | more causes the display to stop after each screen fill.<\/p>\n<p>pwd<br \/>\nPrint working directory, i.e. display the name of your current directory on the screen.<\/p>\n<p>hostname<br \/>\nPrint the name of the local host (the machine on which you are working).<\/p>\n<p>whoami<br \/>\nPrint your login name.<\/p>\n<p>id username<br \/>\nPrint user id (uid) and his\/her group id (gid), effective id (if different than the real id) and the supplementary groups.<\/p>\n<p>date<br \/>\nPrint or change the operating system date and time. E.g., change the date and time to 2000-12-31 23:57 using this command<\/p>\n<p>date 123123572000<br \/>\nTo set the hardware clock from the system clock, use the command (as root)<br \/>\nsetclock<\/p>\n<p>time<br \/>\nDetermine the amount of time that it takes for a process to complete+ other info. Don\u2019t confuse it with date command. For e.g. we can find out how long it takes to display a directory content using time ls<\/p>\n<p>uptime<br \/>\nAmount of time since the last reboot<\/p>\n<p>ps<br \/>\nList the processes that are have been run by the current user.<\/p>\n<p>ps aux | more<br \/>\nList all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.<\/p>\n<p>top<br \/>\nKeep listing the currently running processes, sorted by cpu usage (top users first).<\/p>\n<p>uname -a<br \/>\nInfo on your server.<\/p>\n<p>free<br \/>\nMemory info (in kilobytes).<\/p>\n<p>df -h<br \/>\nPrint disk info about all the file systems in a human-readable form.<\/p>\n<p>du \/ -bh | more<br \/>\nPrint detailed disk usage for each subdirectory starting at root (in a human readable form).<\/p>\n<p>lsmod<br \/>\n(as root. Use \/sbin\/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.<\/p>\n<p>set|more<br \/>\nShow the current user environment.<\/p>\n<p>echo $PATH<br \/>\nShow the content of the environment variable PATH. This command can be used to show other environment variables as well. Use set to see the full environment.<\/p>\n<p>dmesg | less<br \/>\nPrint kernel messages (the current content of the so-called kernel ring buffer). Press q to quit less. Use less \/var\/log\/dmesg to see what dmesg dumped into the file right after bootup. &#8211; only works on dedciated systems<\/p>\n<p>Commands for Process control<br \/>\nps<br \/>\nDisplay the list of currently running processes with their process IDs (PID) numbers. Use ps aux to see all processes currently running on your system (also those of other users or without a controlling terminal),<br \/>\neach with the name of the owner. Use top to keep listing the processes currently running.<\/p>\n<p>fg<br \/>\nPID Bring a background or stopped process to the foreground.<\/p>\n<p>bg<br \/>\nPID Send the process to the background. This is the opposite of fg. The same can be accomplished with Ctrl z<\/p>\n<p>any_command &amp;<br \/>\nRun any command in the background (the symbol \u2018&amp;\u2019 means run the command in the background?).<\/p>\n<p>kill PID<br \/>\nForce a process shutdown. First determine the PID of the process to kill using ps.<\/p>\n<p>killall -9 program_name<br \/>\nKill program(s) by name.<\/p>\n<p>xkill<br \/>\n(in an xwindow terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)<\/p>\n<p>lpc<br \/>\n(as root) Check and control the printer(s). Type ??? to see the list of available commands.<\/p>\n<p>lpq<br \/>\nShow the content of the printer queue.<\/p>\n<p>lprm job_number<br \/>\nRemove a printing job job_number from the queue.<\/p>\n<p>nice program_name<br \/>\nRun program_name adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of niceness to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use top to display the priorities of the running processes.<\/p>\n<p>renice -1 PID<br \/>\n(as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).<\/p>\n<p>Optimising mysql is very well commented on the net, and you\u2019ll find huge information on how to do this. There is never \u201cbest parameters\u201d, the best parameters is those fits your needs, box hardware, mysql usage\u2026<br \/>\nSo, I\u2019ll not give the best parameters but rather how to define these ones. Make some tests, and you\u2019ll quickly find your own parameters.<\/p>\n<p>I\u2019ll give you at the end of this post some web pointers which may help you.<\/p>\n<p>There a lot of available parameters but only few one are very important to tweak your mysql box.<\/p>\n<p>The most important variables are (for me, and it is not exhaustive)<\/p>\n<div>\n<div>\n<div>\n<div><\/div>\n<p>&#8211; max_connections<br \/>\n&#8211; wait_timeout<br \/>\n&#8211; thread_cache_size<br \/>\n&#8211;<br \/>\n&#8211; table_cache<br \/>\n&#8211;<br \/>\n&#8211; key_buffer_size<br \/>\n&#8211; query_cache_size<br \/>\n&#8211; tmp_table_size<\/p><\/div>\n<\/div>\n<\/div>\n<p><span style=\"text-decoration: underline;\"><b>First of all, how to find your variable, and the mysql usage ?<\/b><\/span><\/p>\n<p><b>*VARIABLES<\/b><\/p>\n<div>\n<div>\n<div>\n<div><\/div>\n<p>from mysql :<br \/>\nshow variables;<\/p>\n<p>or from command line :<br \/>\nmysqladmin variables<\/p><\/div>\n<\/div>\n<\/div>\n<p><b>*PROCESS \/ STATUS<\/b><\/p>\n<div>\n<div>\n<div>\n<div><\/div>\n<p>from Mysql :<br \/>\nshow status;<\/p>\n<p>or from command line<br \/>\nmysqladmin \u2013i10 processlist extended-status<\/p><\/div>\n<\/div>\n<\/div>\n<p><b>*SOME USEFUL COMMAND FOR YOU BOX USAGE<\/b><\/p>\n<div>\n<div>\n<div>\n<div><\/div>\n<p>&gt;Top<\/p>\n<p>&gt;ps \u2013axfu<\/p>\n<p>&gt;vmstat 1<\/p><\/div>\n<\/div>\n<\/div>\n<p><b>* OPTIMISING MYSQL<\/b><\/p>\n<p>To obtain the stat of your mysql server since it has been loaded, run mysqladmin processlist extended-status as mentionned above.<\/p>\n<p><b><span style=\"text-decoration: underline;\">1 &#8211; The two most important variables\u00a0<\/span>:\u00a0<span style=\"color: red;\">Table_cache and Key_buffer_size<\/span><\/b><\/p>\n<p><span style=\"color: #006400;\">* If Opened_tables is big, then your table_cache variable is probably<br \/>\ntoo small.<\/span><br \/>\ntable_cache 64<br \/>\nOpen_tables 64<br \/>\nOpened_tables 544468<\/p>\n<p>This is the first serious problem. &#8220;The table_cache is the number of open<br \/>\ntables for all threads. MySQL, being multi-threaded, may be running many<br \/>\nqueries on the table at one time, and each of these will open a table.&#8221;<br \/>\nTherefore, even though we only have a few tables, we will need many more<br \/>\nopen_tables.<\/p>\n<p>The Opened_tables value is high and shows the number of<br \/>\ncache misses. Getting the table_cache size correct is one of the two best<br \/>\nthings you can do to improve performance.<\/p>\n<p><span style=\"color: #006400;\">* If Key_reads is big, then your key_buffer_size variable is probably<br \/>\ntoo small. The cache hit rate can be calculated with<br \/>\nKey_reads\/Key_read_requests.<\/span><br \/>\nkey_buffer_size 16M<br \/>\nKey_read_requests 2973620399<br \/>\nKey_reads 8490571<br \/>\n(cache hit rate = 0.0028)<\/p>\n<p>\u201cThe key_buffer_size affects the size of the index buffers and the speed<br \/>\nof index handling, particularly reading.&#8221; The MySQL manual (and other sources) say that<br \/>\n&#8220;Key_reads\/Key_read_request ratio should normally be &lt; 0.01.&#8221; This is the<br \/>\nother most important thing to get correct. Here the value seems to be correct (&lt; 0.01)<\/p>\n<p>Also check key_write_requests and key_writes.<br \/>\nThe key_writes\/key_writes_request should normally be &lt; 1 (near 0.5 seems to be fine)<\/p>\n<p>Here is a very interesting web pointer :http:\/\/www.databasejournal.com\/features\/mysql\/article.php\/10897_1402311_3<\/p>\n<p><b>2 &#8211;\u00a0<span style=\"text-decoration: underline;\">Others important settings are\u00a0<\/span>:\u00a0<span style=\"color: red;\">Wait_timeout, max_connexion, thread_cache<\/span><\/b><\/p>\n<p><b>A little explanation :<\/b><br \/>\nGeneraly you have a lot of mysql process that are sleeping because wait_timeout are not set low. So I make sure that the wait_timeout is set to a very low value: 15 seconds (for me) . That means MySQL would close any connection that was idle for more than 15 seconds.<\/p>\n<p>The problem is you also have to increment your max_connexion (mine is set to 300) to be sure there is not a lot of idle clients holding connections and blocking out new clients from connecting and getting real work done.<br \/>\nThe pbm is that the box has to create new threads (MySQL is a multi-threaded server) at a very high rate. That may sucks up a measurable amount of CPU time.<\/p>\n<p>So the solution is to use the Thread_cache (from mysql doc) :<br \/>\n\u201cHow many threads we should keep in a cache for reuse. When a client disconnects, the client&#8217;s threads are put in the cache if there aren&#8217;t more than thread_cache_size threads from before. All new threads are first taken from the cache, and only when the cache is empty is a new thread created. This variable can be increased to improve performance if you have a lot of new connections. (Normally this doesn&#8217;t give a notable performance improvement if you have a good thread implementation.) By examing the difference between the Connections and Threads_created you can see how efficient the current thread cache is for you.\u201d<\/p>\n<p><span style=\"color: #006400;\">* If Threads_created is big, you may want to increase the<br \/>\nthread_cache_size variable. The cache hit rate can be calculated with<br \/>\nThreads_created\/Connections.<\/span><br \/>\nthread_cache_size 0<br \/>\nThreads_created 150022<br \/>\nConnections 150023<\/p>\n<p>This is the second problem that should be fixed. A cache size of zero is the default for my-medium.cnf but the recommended size in my-large.cnf is 8.<\/p>\n<p>you may try this formula : table_cache = opened table \/ max_used_connection<\/p>\n<p><b><span style=\"text-decoration: underline;\">3 &#8211; Finally, you may also have a look at\u00a0<\/span>:\u00a0<span style=\"color: red;\">tmp_table_size and Handler_read_rnd \/ Handler_read_rnd_next<\/span>\u00a0<\/b><\/p>\n<p><span style=\"color: #006400;\">* If Created_tmp_disk_tables is big, you may want to increase the<br \/>\ntmp_table_size variable to get the temporary tables memory-based instead<br \/>\nof disk based.<\/span><\/p>\n<p>tmp_table_size 32M<br \/>\nCreated_tmp_disk_tables 3227<br \/>\nCreated_tmp_tables 159832<br \/>\nCreated_tmp_files 4444<\/p>\n<p>Created_tmp_disk_tables are the &#8220;number of implicit temporary tables on<br \/>\ndisk created while executing statements&#8221; and Created_tmp_tables are<br \/>\nmemory-based. Obviously it is bad if you have to go to disk instead of<br \/>\nmemory. About 2% of temp tables go to disk, which doesn&#8217;t seem too bad<br \/>\nbut increasing the tmp_table_size probably couldn&#8217;t hurt either.<\/p>\n<p><span style=\"color: #006400;\">* If Handler_read_rnd is big, then you probably have a lot of queries<br \/>\nthat require MySQL to scan whole tables or you have joins that don&#8217;t use<br \/>\nkeys properly.<\/span><br \/>\nHandler_read_rnd 27712353<br \/>\nHandler_read_rnd_next 283536234<\/p>\n<p>These values are high, that we could probably stand to improve<br \/>\nthe indexes and queries.<\/p>\n<p>I hope this will help some of you to more understand how it is possible to optimise MYSQL to fit your needs, hardaware box, or mysql current usage.<\/p>\n<p>Maybe there is others tweaks to perform, but I know well only these ones. I did setup using these ones on differents mysql box, and generally it did help us to increase performance without have to change hardware (our boxes have 2GB ram)<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SECURING CPANEL &#8211; WHM &#8211; AND ROOT on a VPS This will help but as mentioned in previous posts, with a VPS you do not have access to your kernal. That is good in some ways, because if you don&#8217;t have access to it, neither to hackers or spammers (which limits what they can do). [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[58,60],"tags":[101],"class_list":["post-226","post","type-post","status-publish","format-standard","hentry","category-cpanel-control-panel","category-linux","tag-how-to-secure-and-optimize-your-vps"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}