{"id":177,"date":"2017-12-17T11:35:05","date_gmt":"2017-12-17T11:35:05","guid":{"rendered":"https:\/\/learningcurve.xyz\/?p=177"},"modified":"2017-12-19T04:49:22","modified_gmt":"2017-12-19T04:49:22","slug":"alibaba-cloud-1-secure-an-ubuntu-server","status":"publish","type":"post","link":"https:\/\/learningcurve.xyz\/?p=177","title":{"rendered":"Alibaba Cloud 1 &#8211; Secure an Ubuntu Server"},"content":{"rendered":"<p>This is the first tutorial of a series that will culminate with a fresh WordPress site running on an Alibaba Cloud Instance.<\/p>\n<p>In this tutorial, we will create and secure our instance running Ubuntu. Next we will <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/10\/alibaba-cloud-2-lemp-stack\/\" target=\"_blank\" rel=\"noopener\">complete a modern LEMP stack, with NGINX, MariaDB, and PHP7<\/a>. Then we will run through Domain Management, adding DNS records, and <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/12\/alibaba-cloud-3-lets-encrypt-ssl\/\" target=\"_blank\" rel=\"noopener\">installing a Let&#8217;s Encrypt SSL certificate<\/a>, before finally moving onto <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/12\/alibaba-cloud-4-install-wordpress\/\" target=\"_blank\" rel=\"noopener\">installing WordPress via the CURL and WP-CLI<\/a>. As an added bonus, there is a little extra on setting up a third party SMTP service for transactional emails.<\/p>\n<p>While these tutorials are concerned primarily with configuring an Alibaba Cloud Instance, they should work just as well, with minor changes, for any Cloud VPS provider.<\/p>\n<p>The reason I am using an Alibaba instance is that a client recently asked for a site to be hosted in China, and, for that, they provide the best solution with English language support. However while learning their infrastructure, it became quite clear that they provides a competitive addition to the Cloud Hosting market sector. If you want to experiment with their offering, they provide a $300 USD coupon to be used within 60 days of signing up for their service.<\/p>\n<p>After signing up, and verifying my credit card, I was able to access their services via the Alibaba Cloud Console:<\/p>\n<figure id=\"attachment_109\" aria-describedby=\"caption-attachment-109\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-109 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Alibaba-Cloud-Console-Management-Panel-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-109\" class=\"wp-caption-text\">Alibaba&#8217;s Cloud Console Management Panel<\/figcaption><\/figure>\n<p>You&#8217;ll see the Elastic Compute Services (ECS) link in the top right of the main products and services panel, click that to move through to the ECS overview panel.<\/p>\n<figure id=\"attachment_113\" aria-describedby=\"caption-attachment-113\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-113 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Elastic-Compute-Services-Key-Pairs-600x375.png\" alt=\"ECS Overview Panel\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-113\" class=\"wp-caption-text\">ECS Overview Panel &#8211; Head over to Key Pairs first!<\/figcaption><\/figure>\n<p>At this point, when I first provisioned a server, I rushed straight into &#8216;Instances&#8217;, a natural reaction I&#8217;m sure many will feel the urge to repeat, but hold your horses&#8230;<\/p>\n<p>I advise you to go directly to &#8216;Key Pairs&#8217;, to upload your Public SSH key before you do anything else.<\/p>\n<p>Why, you may ask? Well that&#8217;s because when you provision a server you should attach your public key, and if you haven&#8217;t uploaded one yet, it takes you out of the provisioning workflow and resets any previously selected choices.<\/p>\n<p>So let&#8217;s do that first&#8230;<\/p>\n<p>Wait, whats that you say? Some of you don&#8217;t have an SSH key? Okay then, I guess we&#8217;ll do\u00a0<em>that<\/em> first then.<\/p>\n<h2>Step 1. Uploading your SSH Public Key<\/h2>\n<p>Open the terminal on your <strong>local machine<\/strong>, and enter the following command:<\/p>\n<pre>$ ssh-keygen\r\n<\/pre>\n<p>Assuming your local user were called &#8220;localuser&#8221;, you should see the following in your terminal:<\/p>\n<pre>Generating public\/private rsa key pair.\r\nEnter file in which to save the key (\/Users\/localuser\/.ssh\/id_rsa):\r\n<\/pre>\n<p>This is the common path, so I suggest you just hit return to accept the file name and path.<\/p>\n<p>You will also be prompted for a passphrase to secure the key with, this is optional, adding a password does add an extra layer of security, but it&#8217;s not necessary.<\/p>\n<p>Now you will have generated a both a private key, <span class=\"grey-code\">id_rsa<\/span>, and a public key, <span class=\"grey-code\">id_rsa.pub<\/span>, in the <span class=\"grey-code\">.ssh<\/span> directory of your localuser&#8217;s home directory.<\/p>\n<p>These keys are needed to remote tunnel into your server, so don&#8217;t delete them. By default they are stored in a hidden folder, so they should be safe. On a mac you can always display your hidden folders using <span class=\"grey-code\"> \u21e7(shift) + \u2318(command) + .(period)<\/span> .<\/p>\n<p>Right then, <em>now<\/em> we can upload our public key in the ECS control panel. Just click on the menu link in the screenshot above, it&#8217;s on the left horizontal menu bar in the Network &amp; Security section, and it will take you to the following settings screen:<\/p>\n<figure id=\"attachment_115\" aria-describedby=\"caption-attachment-115\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-115 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Key-Pairs-Settings-Panel-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-115\" class=\"wp-caption-text\">Key Pairs Settings &#8211; Create New Pair<\/figcaption><\/figure>\n<p>As you can see, I already have my public key uploaded, but you will need to the click the link in the top right to create a new key pair.<\/p>\n<p>It will open a new settings panel below:<\/p>\n<figure id=\"attachment_116\" aria-describedby=\"caption-attachment-116\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-116 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/create-new-key-pair-screen-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-116\" class=\"wp-caption-text\">New Key Pair &#8211; Import an Existing Public Key<\/figcaption><\/figure>\n<p>First, name your key pair, then select the &#8216;Import an Existing Key Pair&#8217; radio button. A large black textarea entry box will open, into which you will copy and paste your public key.<\/p>\n<p>Use the following command to print out your public <span class=\"grey-code\">id_rsa.pub<\/span> key in the terminal of your <strong>local machine<\/strong>:<\/p>\n<pre>$ cat ~\/.ssh\/id_rsa.pub\r\n<\/pre>\n<p>Your public key should look something like this:<\/p>\n<pre>ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD0NlbKiLwqNHF\/H+OcQd6ShGz34874837\"\"\";;\r\nsdkniwncnOYrwyUBqkBtulfZObTqh6vhbNxTChUbrIZpICE9wqTYVIvNDRc75bM2YEXBymYpZ4ZE17WwT\r\n+ko2UsxygWC+yxwG9pwvShHw\/PCYxdE232n5l1hQe38VPDlEOBcti8ZRYO42XQxv0jcb86jbpbNoqO2yC\r\nfa\/Aj6hJaSLcbGVdZRAijU\/JCcKd7WTGIIhGWrw43q+HDLuF+9Z local_user@computer.local\r\n<\/pre>\n<p>Select all of this text and copy it to your clipboard, then paste it into the textarea box in the ECS key pairs settings panel from earlier.<\/p>\n<p>Once complete, click OK and you will have created your key pairing, the key will be listed under your chosen key pair name in the key pairs settings screen, and will be available when you provision your Instance.<\/p>\n<h2>Step 2. Provision your EC2 Instance<\/h2>\n<p>Now we will create our ECS instance, head back to the instance Overview panel by following the link in the horizontal side menu. You will be greeted by the following screen:<\/p>\n<figure id=\"attachment_117\" aria-describedby=\"caption-attachment-117\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-117 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Elastic-Compute-Services-Overview-and-Buy-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-117\" class=\"wp-caption-text\">ECS Overview &#8211; Buy Instance = Create New Instance<\/figcaption><\/figure>\n<p>From the overview screen you can see all the locations where servers are available, and in the top right of each location pane there is a little checkout cart symbol link. Click that link.<\/p>\n<p>A new window will open to create an instance, with all the configuration options, and a price bar along the bottom so you can see how configuration changes affect running costs on the fly.<\/p>\n<p>In the &#8216;Advanced Purchase&#8217; tab there are options for paying monthly by subscription, or by paying by the hour, while the &#8216;Starter Packages&#8217; tab offers set configurations, which are available by subscription only:<\/p>\n<figure id=\"attachment_118\" aria-describedby=\"caption-attachment-118\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-118 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Create-Instance-Pricing-Model-and-Datacenter-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-118\" class=\"wp-caption-text\">Choose a Pricing Model &amp; Datacenter<\/figcaption><\/figure>\n<p>For this tutorial I selected &#8216;Pay-As-You-Go&#8217; and the Singapore Datacenter, from the advanced tab The running cost is quite reasonable, but their cheapest starter package is USD $4.50 per month for a 1G server. That&#8217;s a big difference.<\/p>\n<p>Or it would be, if we weren&#8217;t using their free credit.<\/p>\n<p>Next we need to choose our Instance type and Network Type:<\/p>\n<figure id=\"attachment_119\" aria-describedby=\"caption-attachment-119\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-119 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Create-Instance-Instance-and-Network-Type-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-119\" class=\"wp-caption-text\">Choose your Instance &amp; Network type<\/figcaption><\/figure>\n<p>There are 3 generations of instance types, based upon different processor architectures, and in a twist, the latest generation instances are less expensive. I swapped my instance to a Generation III and the cost decreased marginally. Choose whichever configuration suits your needs.<\/p>\n<p>You must also select network type, &#8216;VSwitch&#8217;, and Security Group. However in my experience, there is only one option for each of these in the advanced settings.<\/p>\n<p>The security group is the Alibaba Cloud Firewall, there will only be a default option to select for now. We will be editing this later in the series to open ports for our Let&#8217;s Encrypt SSL.<\/p>\n<p>Next up is the Data Transfer and Operating System configurations:<\/p>\n<figure id=\"attachment_121\" aria-describedby=\"caption-attachment-121\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-121 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Create-Instance-Data-Transfer-and-OS-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-121\" class=\"wp-caption-text\">Set your Network Bandwidth &amp; choose an OS flavour<\/figcaption><\/figure>\n<p>With advanced packages you are also charged by metered Data Transfer, you can set your Network Bandwidth to limit your exposure to higher costs. To be allocated a static IP address, you need to set your Network Bandwidth about 1Mbps.<\/p>\n<p>After that you can choose from a wide range of operating systems and versions. For this series we will be using Ubuntu 16.04 64-bit.<\/p>\n<p>Once these are configured, we move onto Storage and Security Settings:<\/p>\n<figure id=\"attachment_122\" aria-describedby=\"caption-attachment-122\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-122 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Create-Instance-Security-and-Storage-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-122\" class=\"wp-caption-text\">Select your Storage and attach your SSH Public Key<\/figcaption><\/figure>\n<p>For storage they have an &#8216;Ultra Cloud Disk&#8217; or an &#8216;SSD Cloud Disk&#8217;, I chose the fastest option the &#8216;SSD Cloud Disk&#8217;, which has increased the cost per hour by about 30%, but it&#8217;s on their dime so, gimme gimme gimme.<\/p>\n<p>This is also where you attach your SSH Key Pair, if you created it earlier, as I suggested. If you didn&#8217;t and jumped ahead, then you&#8217;ll need to create it now, and restart this configuration process again afterwards. Bet you feel silly now eh?<\/p>\n<p>Okay, nearly there, last but not least you will name your instance and check the overview:<\/p>\n<figure id=\"attachment_123\" aria-describedby=\"caption-attachment-123\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-123 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Create-Instance-Name-and-Overview-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-123\" class=\"wp-caption-text\">Name your instance and check the Overview<\/figcaption><\/figure>\n<p>Choose your name, this will also be the Server&#8217;s hostname. Once you have checked the configuration Overview and are satisfied with your choice, click the &#8216;Buy Now&#8217; button.<\/p>\n<p>Before the instance is activated, you have to confirm your order:<\/p>\n<figure id=\"attachment_124\" aria-describedby=\"caption-attachment-124\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-124 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Confirm-Order-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-124\" class=\"wp-caption-text\">Confirm your order to activate your Instance<\/figcaption><\/figure>\n<p>Click the ECS Service and General Terms and then you&#8217;re free to Activate your brand new instance.<\/p>\n<p>If everything has gone according to plan you should be redirected to the Instances Console Panel, which lists all of your instances for each selected region, along with their IP addresses, general configurations, and links for management and reconfiguration:<\/p>\n<figure id=\"attachment_126\" aria-describedby=\"caption-attachment-126\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-126 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Instances-List-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-126\" class=\"wp-caption-text\">Behold your Instance in all it&#8217;s shiny new Glory!<\/figcaption><\/figure>\n<h2>Step 3. Login as Root<\/h2>\n<p>If you are all done done admiring your shiny new Instance and investigating the various settings, it&#8217;s time to log in.<\/p>\n<p>Copy your instance&#8217;s IP address, open your terminal and log in as <span class=\"grey-code\">root<\/span> user using the following command, remembering to replace <span class=\"grey-code\">your_server_ip<\/span> with the IP address you just copied:<\/p>\n<pre>$ ssh root@<span class=\"green\">your_server_ip<\/span>\r\n<\/pre>\n<p>Assuming you attached the Key Pair correctly during configuration, and you used the correct IP address, then the login process will include a warning about host authenticity, accept the warning and add the key to your known hosts, and your terminal should look like the following:<\/p>\n<figure id=\"attachment_138\" aria-describedby=\"caption-attachment-138\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-138 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/the-root-login-600x408.png\" alt=\"\" width=\"600\" height=\"408\" \/><figcaption id=\"caption-attachment-138\" class=\"wp-caption-text\">Login as root<\/figcaption><\/figure>\n<div class=\"highlighted warning\">\n<h4>A few words about Root<\/h4>\n<p>In a Linux environment the Root user is the administrative user with a very broad range of escalated privileges. It is common practice to discourage the use of the root account on a daily\/regular basis, primarily because this account has such heightened privileges that it&#8217;s very very easy to accidently cause havoc on your system, seemingly innocuous changes can be very destructive.<\/p>\n<\/div>\n<h2>Step 4. Create a New Superuser<\/h2>\n<p>Given the inherent risks of using the root account, our plan is to create a superuser for everyday server managment. To do that we create a new user, and then add them to the Sudo group, this grants them the escalated <span class=\"grey-code\">sudo<\/span> privileges required to make administrative changes on the system when necessary. The use of these sudo privileges will require a password entry from the superuser.<\/p>\n<p>Once we have done this, we will disable remote root access to the server, helping securing it from ne&#8217;er-do-goods and other miscreants.<\/p>\n<p>Create a new user with the following command. The new user I&#8217;ve created for this tutorial is called <span class=\"grey-code\">new_user<\/span>, you should replace that name with one of your choosing:<\/p>\n<pre># adduser <span class=\"green\">new_user<\/span>\r\n<\/pre>\n<div class=\"highlighted warning\">When you&#8217;re in the root user, the terminal command line will begin with the # hash symbol. An account with standard privileges uses the $ line beginning. When you see # remember to be very careful.<\/div>\n<p>You will be asked to provide a password, and add some user details. You should, of course, enter a strong password, but only fill in the additional details only if you like as they aren&#8217;t requisite, hitting <span class=\"grey-code\">ENTER<\/span> in any field will just skip it.<\/p>\n<p>Now you have a new user account with standard privileges, and since we want to disable root login later, we need to add this user to the <span class=\"grey-code\">sudo<\/span> group to create the &#8220;superuser&#8221; with the necessary root privileges to do complete administrative tasks.<\/p>\n<p>To do that issue the following command as <span class=\"grey-code\"> root <\/span>:<\/p>\n<pre># usermod -aG sudo <span class=\"green\">new_user<\/span>\r\n<\/pre>\n<p>Your terminal screen should now look like this:<\/p>\n<figure id=\"attachment_140\" aria-describedby=\"caption-attachment-140\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-140 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/Add-new-user-and-escalate-to-superuser-600x428.png\" alt=\"\" width=\"600\" height=\"428\" \/><figcaption id=\"caption-attachment-140\" class=\"wp-caption-text\">Add a new superuser<\/figcaption><\/figure>\n<h2>Step 5. Add Public Key Authentication to your Superuser<\/h2>\n<p>Remember the Public Key we added to our Alibaba account? That key is only available to the root user, therefore if we disabled root login now it would be impossible for our <span class=\"grey-code\">new_user<\/span> to login.<\/p>\n<p>That means we need to add that public key to a soon-to-be-created <span class=\"grey-code\">.ssh<\/span> directory in our <span class=\"grey-code\">new_user<\/span>&#8216;s home directory.<\/p>\n<p>First we need to switch to the <span class=\"grey-code\">new_user<\/span> from <span class=\"grey-code\">root<\/span> user by entering the following command:<\/p>\n<pre>$ su - <span class=\"green\">new_user<\/span>\r\n<\/pre>\n<p>Now we are in the <span class=\"grey-code\">new_user<\/span>&#8216;s home directory, located here in the full path <span class=\"grey-code\"> \/home\/new_user\/ <\/span>.<\/p>\n<p>Create a new directory called <span class=\"grey-code\">.ssh<\/span>, and restrict its permissions, with the following command:<\/p>\n<pre>$ mkdir ~\/.ssh\r\n$ chmod 700 ~\/.ssh\r\n<\/pre>\n<p>Now, create and open a file in the <span class=\"grey-code\">.ssh<\/span> directory called <span class=\"grey-code\">authorized_keys<\/span>, using the built in nano text editor:<\/p>\n<pre>$ nano ~\/.ssh\/authorized_keys\r\n<\/pre>\n<p>Copy the same public key from earlier, <span class=\"grey-code\">id_rsa.pub<\/span>, and paste it into the editor. Enter <span class=\"grey-code\">CTRL + X<\/span> to exit the file, and <span class=\"grey-code\"> y <\/span> to save the changes, then <span class=\"grey-code\">ENTER<\/span> to confirm the correct file name.<\/p>\n<p>Once this is completed we need to restrict the permissions of the <span class=\"grey-code\">authorized_keys<\/span> file, and return to the <span class=\"grey-code\">root<\/span> user with the following commands:<\/p>\n<pre>$ chmod 600 ~\/.ssh\/authorized_keys\r\n$ exit\r\n<\/pre>\n<h2>Step 6. Disable Password Authentication and Root Login<\/h2>\n<p>With your public key installed and accessible, your <span class=\"grey-code\">new_user<\/span> will be able to login to the Instance directly. That means we can now further secure the server by disabling password-only authentication, and root login.<\/p>\n<p>Doing this will restrict access to your server to Public Key Authentication only, meaning that the only way for someone to login to your server is if they possess the private key that pairs with the public key previously installed. In addition, disabling root login means that evern if someone did manage to get your private key, they would still be locked out unless they also knew your password.<\/p>\n<p>If you have been following along exactly, you will be in the root account, if however you are still in your new superuser account, then just add <span class=\"grey-code\">sudo<\/span> before each of the following commands.<\/p>\n<p>Open the SSH daemon configuration file for editing:<\/p>\n<pre># nano \/etc\/ssh\/sshd_config\r\n<\/pre>\n<p>We are looking for 4 settings. We need to set <span class=\"grey-code\">PasswordAuthentication no<\/span>, <span class=\"grey-code\">PermitRootLogin no<\/span>, <span class=\"grey-code\">PubkeyAuthentication yes<\/span>, and finally, <span class=\"grey-code\">ChallengeResponseAuthentication no<\/span>.<\/p>\n<p>Here are some screenshots from my system to show you the correct settings:<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-141 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/RootLogin-and-PasswordAuthentication-600x553.png\" alt=\"\" width=\"600\" height=\"553\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">PermitRootLogin no | PasswordAuthentication no<\/figcaption><\/figure>\n<figure id=\"attachment_142\" aria-describedby=\"caption-attachment-142\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-142 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/PubKeyAuthentication-600x552.png\" alt=\"\" width=\"600\" height=\"552\" \/><figcaption id=\"caption-attachment-142\" class=\"wp-caption-text\">PubKeyAuthentication yes<\/figcaption><\/figure>\n<figure id=\"attachment_143\" aria-describedby=\"caption-attachment-143\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-143 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/ChallengeResponse-600x553.png\" alt=\"\" width=\"600\" height=\"553\" \/><figcaption id=\"caption-attachment-143\" class=\"wp-caption-text\">ChallengeResponseAuthentication no<\/figcaption><\/figure>\n<p>With those settings saved, your server should only be accessible by logging in with your superuser account.<\/p>\n<h2>Step 7. Test Superuser Login and Disabled Root Login<\/h2>\n<p>That being said, don&#8217;t go rushing and logging out of your server until we&#8217;ve confirmed everything is working as it should, otherwise our server will be inaccessible from the terminal, and would require resetting the <span class=\"grey-code\">root<\/span> login from the Alibaba console.<\/p>\n<p>Not that I am speaking from experience, of course not, not me&#8230; well not with Alibaba Cloud at least.<\/p>\n<p>Open a new terminal on your <strong>local machine<\/strong>, and login to your server using the new account that you created. Remember to replace <span class=\"grey-code\">new_user<\/span> and <span class=\"grey-code\">your_server_ip<\/span> with your superuser and Instances&#8217;s IP address:<\/p>\n<pre>$ ssh <span class=\"orange\">new_user<\/span>@<span class=\"green\">your_server_ip<\/span>\r\n<\/pre>\n<p>If all our configurations have been correct then you should see something like:<\/p>\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-144 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/new_user-login-600x553.png\" alt=\"\" width=\"600\" height=\"553\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">Test your new user login before logging out of root!<\/figcaption><\/figure>\n<p>Well done, your superuser now has login access to your server via SSH public key authentication.<\/p>\n<p>Just one more thing to test, we need to make sure that root login has been disabled. To do that, attempt to login as root using the following command:<\/p>\n<pre>$ ssh root@<span class=\"green\">your_server_ip<\/span>\r\n<\/pre>\n<p>I needn&#8217;t reminding you to replace <span class=\"grey-code\"> your_server_ip <\/span> with your Instances&#8217;s IP, need I?<\/p>\n<p>All being well, I hope you see something like the following:<\/p>\n<figure id=\"attachment_145\" aria-describedby=\"caption-attachment-145\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-145 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/root-login-denied-600x113.png\" alt=\"\" width=\"600\" height=\"113\" \/><figcaption id=\"caption-attachment-145\" class=\"wp-caption-text\">Ensure root login is denied!<\/figcaption><\/figure>\n<h2>Step 8. Configure Ubuntu&#8217;s UFW firewall<\/h2>\n<p>The last thing we are going to do in this tutorial, is set up the simple firewall that comes with Ubuntu, aptly name UFW, the Uncomplicated Fire Wall.<\/p>\n<p>It is both very easy to configure, and gives some level of protection from nefarious attacks.<\/p>\n<p>Whenever applications are installed to Ubuntu they register their profiles with UFW, this allows the firewall to, very easily, manage the applications by name.<\/p>\n<p>We need to configure UFW to allow SSH connections before we enable it, so we can still log in, otherwise there may be tears.<\/p>\n<p>Since OpenSSH already has a profile registered with UFW you will be able to see it by typing the following command. And remember, now we are logged in as our superuser, we need to type <span class=\"grey-code\">sudo<\/span> before each command that requires administrative privileges:<\/p>\n<pre>$ sudo ufw app list\r\n<\/pre>\n<p>Which should return:<\/p>\n<pre>Available applications:\r\nOpenSSH\r\n<\/pre>\n<p>To ensure SSH connections are allowed through the firewall we can instruct UFW by issuing the following:<\/p>\n<pre>$ sudo ufw allow OpenSSH\r\n<\/pre>\n<p>After doing this, we can safely enable the firewall by entering:<\/p>\n<pre>$ sudo ufw enable\r\n<\/pre>\n<p>It will issue a warning, and require you to type <span class=\"grey-code\"> y <\/span> and press <span class=\"grey-code\">ENTER<\/span>. Once completed, you can verify that SSH connections are allowed through the UFW by issuing the following command:<\/p>\n<pre>$ sudo ufw status\r\n<\/pre>\n<p>The above combination of commands and outputs should result in a terminal that looks like the following:<\/p>\n<figure id=\"attachment_146\" aria-describedby=\"caption-attachment-146\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-146 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/UFW-600x352.png\" alt=\"\" width=\"600\" height=\"352\" \/><figcaption id=\"caption-attachment-146\" class=\"wp-caption-text\">Configure UFW to allow OpenSSH connections<\/figcaption><\/figure>\n<p>And that&#8217;s it.<\/p>\n<p>We have now provisioned an Alibaba Cloud EC2 Instance with an Ubuntu 16.04 installation, and performed some of the necessary actions to secure it.<\/p>\n<p>We now have a versatile foundation upon which to complete the LEMP stack, which we will do in the next tutorial.<\/p>\n<p>See you then.<\/p>\n<p>Jeff<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the first tutorial of a series that will culminate with a fresh WordPress site running on an Alibaba Cloud Instance. In this tutorial, we will create and secure our instance running Ubuntu. Next we will complete a modern LEMP stack, with NGINX, MariaDB, and PHP7. Then we will run through Domain Management, adding [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177"}],"version-history":[{"count":4,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions\/179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/media\/172"}],"wp:attachment":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}