Set up a web server on Amazon Web Services

Creating the instance on AWS

  • Point your browser to https://aws.amazon.com and select My Account \(\to\) AWS Management Console.
  • Choose Root user and log in with your email address. If you do not have an account you first need to create one.
  • Choose Build using virtual servers (with Lightsail).
  • Make the following selections.
    • Platform: Linux/Unix
    • Blueprint: OS Only, then select Ubuntu 20.04 LTS.
    • Instance plan: It is sufficient to choose the one that costs \(\$5\) a month. It has 1GB RAM, 1 vCPU, 40 GB SSD, and 2TB transfer.
  • Choose a name for your instance and click Create instance
  • You will see the word Pending. If nothing happens for two minutes, you can click refresh button of your browser you should see the newly created instance.
  • Write down the IP address that was assigned to your instance. You will need this later. Then, click on the console icon.

Configuring SSH

  • Add a user for your server. We chose the username mprogrammer for this tutorial. You may wish to select some other name. The command to create user is
    sudo adduser mprogrammer
    Make sure you choose a password that is secure. We will set up the server so it can be accessed using the password only.
  • Give the new user the powers to be the administrator.
    sudo usermod -a -G sudo mprogrammer
  • We will now modify the ssh configuration to allow remote access using the username and password only. This is useful if you are using multiple computers to administer your server. Setting up pairs of public and private keys would make this tutorial a bit longer.
    • Execute the command
      sudo nano /etc/ssh/sshd_config
    • Locate the line that contains the word PermitRootLogin. It is very likely that it starts with the symbol #. This means that the line is commented-out and inactive. You need to erase that leading # and modify it a bit so the line has the following form:
      PermitRootLogin no
    • Locate the line with PasswordAuthentication no. Change this line to
      PasswordAuthentication yes
    • Click Ctrl+x. Then type y and then click enter.
  • Restart the server by typing
    sudo reboot
    You will need to wait for about two minutes before the server can be accessed again.

Connecting to the server using an SSH program

  • Open the terminal program from your own computer
  • Use the IP address of your server from the website. Assume that it is 11.22.333.444. Type the following command in your terminal program.
    ssh mprogrammer@11.22.333.444
    Answer yes to a few questions that the terminal may ask you.
  • If your computer is giving you problems and does not let you access the server even, then most likely you did not wait long enough for the server to restart. If after 10 minutes you still have problems, then you may need to execute this command:
    ssh-keygen -R 11.22.333.444
  • Type the command
    sudo apt update
    Type your password and wait for the command to finish.
  • Type
    sudo apt upgrade
    This may take two minutes or longer.
  • Reboot the server with
    sudo reboot
  • You need to ssh to the website again.