Re-installing the operating system on AWS Instance

Warning: Do not do this, unless things became very broken. This will erase all your data on the server, and re-start the procedure.


If you want to completely re-install the operating system, then you need to do the following four steps in this odrer:

  • Create the new instance;
  • Perform basic configurations that must include: add sudo users and configure ssh;
  • Re-assign the static IP from the old to the new instance;
  • Delete the old instance.

Creating the instance on AWS

  • Point your browser to 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.

Detach the static IP from the old instance and attach it to the new instance

The home page of the Amazon LightSail should display all instances that you have. You should click on the old instance, select the networking tab, and then locate the static IP address (in the panel called PUBLIC IP) and then click on the link that contains the custom name of the static IP address.

Now you will see the main page of the static IP address. You can click on the link detach.

After the static IP is detached, you will see a new menu with all available instances. You can select the newly created instance and attach the static IP to it.

You may not be allowed to use ssh from your local computer yet. If that is the case, then you need to run the command

ssh-keygen -R