{"id":912,"date":"2015-10-16T09:40:17","date_gmt":"2015-10-16T00:40:17","guid":{"rendered":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/?page_id=912"},"modified":"2016-07-28T12:40:06","modified_gmt":"2016-07-28T03:40:06","slug":"security","status":"publish","type":"page","link":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/document\/security\/","title":{"rendered":"Security Recommendations"},"content":{"rendered":"<p>This guide explains some recommended security measures to perform after installing KUSANAGI.<\/p>\n<h2>1. Enhance security of wp-config.php<\/h2>\n<p>wp-config.php includes information about database connections and also some critical security information such as the unique authentication key. Therefore, it is important to enhance the security of the wp-config.php file.<\/p>\n<h3>a. Move wp-config.php file to the document root<\/h3>\n<p>wp-config.php file is generated under the root directory when WordPress is installed.<br \/>\nMove wp-config.php to the document root so that the file cannot be accessed directly from outside via URL.<\/p>\n<h4>1. Log in to the virtual machine<\/h4>\n<p>Use Poderosa or another SSH client software to log in to the virtual machine via SSH.<\/p>\n<p>Username for login: kusanagi<br \/>\nPassword is the one specified when performing \u201ckusanagi init\u201d.<\/p>\n<blockquote><p>For Microsoft Azure, use the username and password that were specified during the <a href=\"https:\/\/kusanagi.tokyo\/en-kusanagi8\/cloud\/kusanagi-for-microsoft-azure\/#basics\">&#8220;Basics&#8221; screen<\/a> while launching the VM.<\/p><\/blockquote>\n<h4>2. Switch to root user<\/h4>\n<p>Enter the following to switch to root user.<\/p>\n<pre><code>$ su -<\/code><\/pre>\n<p>You will be asked for a password. Enter the password for root user.<br \/>\n<small>* The root user password is the one defined when the virtual machine was launched on the cloud service.<\/small><\/p>\n<blockquote><p>For Microsoft Azure, enter the following to switch to root user.<\/p>\n<pre><code>$ sudo su -<\/code><\/pre>\n<p>You will be asked for a password. Enter the password used for SSH login.<\/p><\/blockquote>\n<h4>3. Go to the directory where wp-config.php is located<\/h4>\n<p>Go to the directory where wp-config.php is located.<br \/>\nEnter the following.<\/p>\n<pre><code># cd \/home\/kusanagi\/kusanagi_html(*1)\/DocumentRoot<\/code><\/pre>\n<p><small>(*1) Enter the name of the profile created in <a href=\"https:\/\/kusanagi.tokyo\/en-kusanagi8\/document\/kusanagi-provision\/\">&#8220;WordPress Provisioning&#8221;<\/a>.<\/small><\/p>\n<h4>4. Move wp-config.php up one level<\/h4>\n<p>Move the wp-config.php file up one level. Enter the following.<\/p>\n<pre><code># mv wp-config.php ..\/<\/code><\/pre>\n<h4>5. Go up one level from current directory<\/h4>\n<p>Go up one level from the current directory and confirm that wp-config.php has been moved correctly. Enter the following.<\/p>\n<pre><code># cd ..<\/code><\/pre>\n<h4>6. Confirm wp-config.php file is present<\/h4>\n<p>Check that \u201cwp-config.php\u201d file is in the document root.<br \/>\nEnter the following to show the list of files in the directory. Make sure wp-config.php is in the list.<\/p>\n<pre><code># ll<\/code><\/pre>\n<p>If the file is there, then the transfer is successful.<\/p>\n<h4>7. Check display of the website<\/h4>\n<p>Access the URL of the website from your browser.<br \/>\nIf the front page of the website displays without any problems, then WordPress is operating normally after the transfer of wp-config.php<\/p>\n<h3>b. Set limited permission<\/h3>\n<p>If you used KUSANAGI to install WordPress, the owner of wp-config.php is httpd (group is www) and the permission is 666 (rw-rw-rw-) by default.<\/p>\n<p>You can increase the security by changing the owner of wp-config.php and set the permission as low as possible.<\/p>\n<p><small>* The following procedures are based on the assumption that wp-config.php has been moved to the document root as shown in the previous step.<\/small><\/p>\n<h4>1. Log in to the virtual machine<\/h4>\n<p>Use Poderosa or another SSH client software to log in to the virtual machine via SSH.<\/p>\n<h4>2. Switch to root user<\/h4>\n<p>Enter the following to switch to root user.<\/p>\n<pre><code>$ su -<\/code><\/pre>\n<p>You will be asked for a password. Enter the password for root user.<br \/>\n<small>* The root user password is the one defined when the virtual machine was launched on the cloud service.<\/small><\/p>\n<blockquote><p>For Microsoft Azure, enter the following to switch to root user.<\/p>\n<pre><code>$ sudo su -<\/code><\/pre>\n<p>You will be asked for a password. Enter the password used for SSH login.<\/p><\/blockquote>\n<h4>3. Go to the directory wp-config.php is located<\/h4>\n<p>Enter the following to go to the directory where wp-config.php is located.<\/p>\n<pre><code># cd \/home\/kusanagi\/kusanagi_html(*1)<\/code><\/pre>\n<p><small>(*1) Enter the name of the profile created in <a href=\"https:\/\/kusanagi.tokyo\/en-kusanagi8\/document\/kusanagi-provision\/\">&#8220;WordPress Provisioning&#8221;<\/a>.<\/small><\/p>\n<h4>4. Change the owner of wp-config.php<\/h4>\n<p>Enter the following to change the owner from web server to kusanagi user.<\/p>\n<pre><code># chown kusanagi.www wp-config.php<\/code><\/pre>\n<h4>5. Change permission for wp-config.php<\/h4>\n<p>After changing the owner, change the permission of wp-config.php to \u201c440 (r-- r-- ---)\u201d to make it unwritable.<br \/>\nEnter the following.<\/p>\n<pre><code># chmod 0440 wp-config.php<\/code><\/pre>\n<h4>6. Check the permission<\/h4>\n<p>Make sure the permission of wp-config.php has been changed. Enter the following to show the list of files in the directory and their permissions. Check the permission of wp-config.php.<\/p>\n<pre><code># ll<\/code><\/pre>\n<p>If the permission of wp-config.php is stated as \u201cr-- r-- ---\u201d, then the change is successful.<\/p>\n<h4>7. Check the display of the site<\/h4>\n<p>Access the URL of the website from your browser.<br \/>\nIf the front page of the website displays without any problems, then WordPress is operating normally after the permission change.<\/p>\n<h3>2. Restrict access to WordPress dashboard<\/h3>\n<p>Prevent unauthorized login from a third party to WordPress dashboard through Basic authentication and restricted IP access.<\/p>\n<p>In KUSANAGI, there are 2 web servers (Nginx and Apache) installed and you can switch to either of them. Follow the next procedures and the settings will function correctly on both servers.<\/p>\n<h4>a. Specify IP address allowed for access on Nginx<\/h4>\n<p>Enter the following to open Nginx configuration file.<\/p>\n<pre><code># vi \/etc\/nginx\/conf.d\/[profile name(*1)]_http.conf<\/code><\/pre>\n<p>(*1) Name of profile created by &#8220;kusanagi provision&#8221; command.<br \/>\nExample: vi \/etc\/nginx\/conf.d\/kusanagi_html_http.conf<\/p>\n<p>In line 43,<br \/>\nchange \u201callow 0.0.0.0\/0;\u201d to the allowed IP address.<br \/>\nExample:allow xxx.xxx.xxx.xxx;<\/p>\n<p><small>* If you don\u2019t use Basic authentication, please comment out lines 46 and 47. (Add \u201c#\u201d to the beginning of the lines)<\/small><\/p>\n<p>At the time of WordPress provisioning, a configuration file is also created for SSL. Thus, the following procedures are also needed.<br \/>\nEnter the following to open Nginx configuration file.<\/p>\n<pre><code># vi \/etc\/nginx\/conf.d\/[profile name (*1)]_ssl.conf<\/code><\/pre>\n<p>(*1) Name of profile created by &#8220;kusanagi provision&#8221; command.<br \/>\nExample: vi \/etc\/nginx\/conf.d\/kusanagi_html_ssl.conf<\/p>\n<p>In line 54<br \/>\nchange \u201callow 0.0.0.0\/0;\u201d to the allowed IP address.<br \/>\nExample: allow xxx.xxx.xxx.xxx;<\/p>\n<p><small>* If you don\u2019t use Basic authentication, please comment out lines 57 and 58. (Add \u201c#\u201d to the beginning of the lines)<\/small><\/p>\n<p>If you are using Nginx and want to reflect the change immediately, please run \u201ckusanagi nginx\u201d command.<br \/>\nThe next time Nginx is launched as the web server, only the specified IP address is allowed to directly access WordPress dashboard.<\/p>\n<p>* Refer to \u201cc. .htpasswd settings\u201d for how to set up username and password for Basic authentication.<\/p>\n<h4>b. Specify IP address permitted for access to Apache<\/h4>\n<p>Enter the following to open \u201c.htaccess\u201d file under the document root.<\/p>\n<pre><code># vi \/home\/kusanagi\/[profile name (*1)]\/DocumentRoot\/.htaccess<\/code><\/pre>\n<p>(*1) Name of profile created by &#8220;kusanagi provision&#8221; command.<br \/>\nExample: vi \/home\/kusanagi\/kusanagi_html\/DocumentRoot\/.htaccess<\/p>\n<p>In line 8<br \/>\nChange &#8220;Allow from all&#8221; to the allowed IP address<br \/>\nExample: Allow from xxx.xxx.xxx.xxx<\/p>\n<p><small>* If you don\u2019t use Basic authentication, please comment out lines 10, 11 and 12. (Add \u201c#\u201d at the beginning of the lines)<\/small><\/p>\n<p>The next time Apache is launched as the web server, only the specified IP address is allowed to directly access WordPress dashboard.<\/p>\n<p>* Refer to \u201cc.\u00a0 .htpasswd settings\u201d for how to set up username and password for Basic authentication.<\/p>\n<h4>c. .htpasswd\u201d settings<\/h4>\n<p>Follow the procedures to create .htpasswd file and set up username and password for Basic authentication.<\/p>\n<h4>1. Create .htpasswd file<\/h4>\n<p>Both in Nginx and Apache, the \u201c.htpasswd\u201d file is set to refer to a common path by default.<br \/>\nCreate \u201c.htpasswd\u201d file in the specified path.<\/p>\n<p>Enter the following.<\/p>\n<pre><code># htpasswd -c \/home\/kusanagi\/.htpasswd [username]<\/code><\/pre>\n<p>Then enter a password.<br \/>\nRe-enter the same password to confirm.<\/p>\n<p>Enter the username and password for the Basic authentication. If the dashboard is displayed with no problem, then the configuration is successful.<\/p>\n<h3>3. Restrict IP access to the server<\/h3>\n<p>You can specify the IP and host that are allowed to connect to hosts.allow file and hosts.deny file. This will deny access to the server from other IP addresses and hosts except the allowed ones.<\/p>\n<ul>\n<li>hosts.allow<br \/>\nSpecify conditions for access permission.<\/li>\n<li>hosts.deny<br \/>\nSpecify conditions for access denial.<\/li>\n<\/ul>\n<p>The settings will be applied in the following order.<\/p>\n<ol>\n<li>If the access matches the conditions set in hosts.allow file, then the access is allowed.<\/li>\n<li>If the access matches the conditions set in hosts.deny file, then the access is denied.<\/li>\n<li>If the access does not match either condition set in hosts.allow or hosts.deny files, then the access is allowed.<\/li>\n<\/ol>\n<p>Use the following format for both hosts.allow file and hosts.deny file.<\/p>\n<pre><code>Service Name: host name or IP address\r\nExample) ssh:192.168.1.0<\/code><\/pre>\n<h4>a. Allow access by hosts.allow<\/h4>\n<p>Specify the IP addresses or host names that are allowed access.<\/p>\n<h5>1. Go to directory where hosts.allow is located<\/h5>\n<p>Enter the following.<\/p>\n<pre><code># cd \/etc\/<\/code><\/pre>\n<h5>2. Open hosts.allow file<\/h5>\n<p>Go to \u201c\/etc\/\u201d directory and open hosts.allow file.<br \/>\nEnter the following.<\/p>\n<pre><code># vi hosts.allow<\/code><\/pre>\n<h5>3. Describe conditions for allowed access<\/h5>\n<p>Describe the conditions for allowed access to the server.<\/p>\n<pre><code>Example\r\nall:192.168.1.10\r\nall:192.168.10.\r\nall:.ucom.ne.jp<\/code><\/pre>\n<p>Add conditions and then save the file.<br \/>\nPlease pay close attention when entering numbers, because if you enter a wrong number in the conditions, you won\u2019t be allowed access.<\/p>\n<h4>b. Deny access by hosts.deny<\/h4>\n<p>Deny all access.<br \/>\nThe hosts.deny file is in the same layer of hosts.allow file.<\/p>\n<h5>1. Open hosts.deny file<\/h5>\n<p>Open hosts.deny file.<br \/>\nEnter the following.<\/p>\n<pre><code># vi hosts.deny<\/code><\/pre>\n<h5>2. Description to deny any access<\/h5>\n<p>Add the following description to deny all access.<\/p>\n<pre><code>all:all<\/code><\/pre>\n<p>Now, only access from the IP address and host name specified in &#8220;a. Allow access by hosts.allow&#8221; are allowed.<br \/>\nSave the file after making changes.<\/p>\n<h3>4. Other directory permission settings<\/h3>\n<p>In KUSANAGI, permission of the following directories is 777 (rwx rwx rwx). Change the permission to 755 (rwx rw- rw-).<\/p>\n<p>\u30fbDocument root (\/home\/kusanagi\/[profile name]\/DocumentRoot)<br \/>\n\u30fbwp-content directory (\/home\/kusanagi[profile name]\/DocumentRoot\/wp-content)<\/p>\n<h4>a. Change permission for DocumentRoot<\/h4>\n<p>Enter the following and go to the directory where DocumentRoot is located.<\/p>\n<pre><code># cd \/home\/kusanagi\/kusanagi_html(*1)<\/code><\/pre>\n<p><small>(*1) Enter the name of the profile created by &#8220;kusanagi provision&#8221; command.<\/small><br \/>\nThen, enter the following.<\/p>\n<pre><code># chmod 0755 DocumentRoot<\/code><\/pre>\n<h4>b. Change permission for wp-content directory<\/h4>\n<p>Next, change the permission for wp-content directory.<br \/>\nEnter the following and go to the directory where wp-content directory is located.<\/p>\n<pre><code># cd DocumentRoot<\/code><\/pre>\n<p>Then, enter the following.<\/p>\n<pre><code># chmod 0755 wp-content<\/code><\/pre>\n<p>The directory permission is now successfully changed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide explains some recommended security measures to perform after installing KUSANAGI. 1. Enhance security of wp-config.php wp-config.php includes information about database connections and also some critical security information such as the unique authentication key. Therefore, it is important to enhance the security of the wp-config.php file. a. Move wp-config.php file to the document root [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":784,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-912","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/pages\/912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/comments?post=912"}],"version-history":[{"count":33,"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/pages\/912\/revisions"}],"predecessor-version":[{"id":1935,"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/pages\/912\/revisions\/1935"}],"up":[{"embeddable":true,"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/pages\/784"}],"wp:attachment":[{"href":"https:\/\/kusanagi.tokyo\/en-kusanagi8\/wp-json\/wp\/v2\/media?parent=912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}