Looking for the Amazon Lightsail Ubuntu 18.04 LTS Upgrade Guide?
While writing my article on installing OLS on Amazon Lightsail, I experimented with upgrading Ubuntu 16.04 LTS to Ubuntu 18.04 LTS using the guide at nixCraft. Great guide, but it fails to mention that upgrading Ubuntu 16.04 LTS to Ubuntu 18.04 LTS on Amazon Lightsail breaks the Lightsail Browser SSH client. The error message simply says:
An error occurred and we were unable to connect or stay connected to your instance. If this instance has just started up, try again in a minute or two. UPSTREAM_NOT_FOUND [519]
As a result, here is my guide, which fixes the error before it happens. All the commands in this article can be run by connecting to the instance from the Amazon Lightsail dashboard with the Lightsail Browser SSH client.
Check Swap Space
In my tests, I used the smallest Amazon Lightsail instance, with 512MB RAM. The installation was Ubuntu 16.04 LTS OS-only, so it didn’t have any default swap space. The first upgrade I performed, without swap space, was killed by the system due to running out of memory.
Check that you have swap space!
cat /proc/swaps
If your instance does not have swap space allocated, you can run the following command to allocate 2GB of swap space. Swap space should be twice the size of the instance’s RAM, unless the instance has more than 2GB of RAM. It is not necessary to reboot after allocating swap space – it will start to be used immediately after being made active.
TL;DR
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile && sudo sed -i '$ a\/swapfile swap swap defaults 0 0' /etc/fstab
Long Version (explanation of the above command string – do not run as separate commands)
Run the command as the root user.
sudo
Allocate space to a file.
fallocate
Specify the length of the file.
-l
Specify the length as 2GB.
2G
Create the file in / with the name “swapfile”.
/swapfile
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Change mode for a file.
chmod
Change the mode to 6(Owner can Read&Write,Not Execute) 0 (Group cannot Read, Write or Execute) 0 (Public cannot Read, Write or Execute).
600
The file that we want to change the mode for is “/swapfile”.
/swapfile
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Prepare a block to be used as swap.
mkswap
The block we want to prepare is “/swapfile”.
/swapfile
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Enable a device of file to be used as swap space.
swapon
The file to use as swap space is “/swapfile”.
/swapfile
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Run SEd
sed
Make changes in-place (in the file we’re editing)
-i
The expression for changes we want to make (add the string to the end of the file)
(Write “/swapfile swap swap defaults 0 0” to /etc/fstab. Fstab is the file system table. The line adds a filesystem of /swapfile with mount point “swap” as type “swap” with options “default”, dump disabled (0) and pass disabled (0). This filesystem will be mounted at reboot because it has been added to fstab.)
'$ a\/swapfile swap swap defaults 0 0'
The file we are editing is
/etc/fstab
Upgrade Ubuntu 16.04 LTS’s Packages
Ubuntu 16.04 LTS will not upgrade to Ubuntu 18.04 LTS without having its own packages updated first.
TL;DR
sudo apt update && sudo DEBIAN_FRONTEND=noninteractive apt -o Dpkg::Options::="--force-confold,confdef" -y full-upgrade && sudo reboot
Long Version (explanation of the above command string – do not run as separate commands)
Run the command as the root user.
sudo
Run the Advanced Package Tool.
apt
Update the list of available packages from sources.
update
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Tell the package manager to run in non-interactive mode.
DEBIAN_FRONTEND=noninteractive
Run the Advanced Package Tool.
apt
Use the following options.
-o
Set the dpkg options to force using of the old configuration file if it exists, else use the default configuration for the package.
Dpkg::Options::="--force-confold,confdef"
Assume yes to all prompts.
-y
Do a full system package upgrade – if removal of installed packages is required, remove them.
full-upgrade
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Reboot the system
reboot
Upgrade Ubuntu 16.04 LTS to Ubuntu 18.04 LTS
We are now ready to upgrade Ubuntu 16.04 LTS to Ubuntu 18.04 LTS and fix the issue with the Amazon Lightsail Browser SSH client at the same time.
(Want to upgrade from Ubuntu 16.04 LTS to Ubuntu 20.04 LTS? Upgrade to Ubuntu 18.04 LTS first, then follow the Ubuntu 18.04 LTS to Ubuntu 20.04 LTS upgrade guide. A direct upgrade is not possible.)
TL;DR
sudo do-release-upgrade -d -f DistUpgradeViewNonInteractive && sudo sed -i -e '/UsePrivilegeSeparation/d' -e '/KeyRegenerationInterval/d' -e '/ServerKeyBits/d' -e '/RSAAuthentication/d' -e '/RhostsRSAAuthentication/d' /etc/ssh/sshd_config && sudo reboot
Long Version (explanation of the above command string – do not run as separate commands)
Run the command as the root user.
sudo
Run the upgrade manager.
do-release-upgrade
Upgrade to the next development release.
-d
Upgrade with the following frontend.
-f
Tell the upgrade manager to run with the non-interactive frontend (old configurations are kept if they exist – if they do not, the default configuration is used).
DistUpgradeViewNonInteractive
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Run SEd
sed
Perform the operations in-place (in the file we are reading from)
-i
Use the expression
-e
Find the expression “UsePrivilegeSeparation” and delete the line in which it appears (d)
'/UsePrivilegeSeparation/d'
Use the expression
-e
Find the expression “KeyRegenerationInterval” and delete the line in which it appears (d)
'/KeyRegenerationInterval/d'
Use the expression
-e
Find the expression “ServerKeyBits” and delete the line in which it appears (d)
'/ServerKeyBits/d'
Use the expression
-e
Find the expression “RSAAuthentication” and delete the line in which it appears (d)
'/RSAAuthentication/d'
Use the expression
-e
Find the expression “RhostsRSAAuthentication” and delete the line in which it appears (d)
'/RhostsRSAAuthentication/d'
Use this file for these operations
/etc/ssh/sshd_config
If the previous command executed successfully, do the next, else stop.
&&
Run the command as the root user.
sudo
Reboot the system
reboot
Amazon Lightsail Browser SSH Client Error 519 After Upgrade
Using this method, we will have avoided the “Upstream Not Found [519]” error message in the Amazon Lightsail Browser SSH client.
Why Does The Upstream Not Found [519] Error Happen?
Ubuntu 16.04 LTS uses OpenSSH Version 7.2, whereas Ubuntu 18.04 LTS uses OpenSSH Version 7.6. In OpenSSH Version 7.6, deprecated settings from Version 7.2 causes problems in the Amazon Lightsail Browser SSH client connection. By removing these deprecated settings from the SSH Configuration File (/etc/ssh/sshd_config), we restore the ability of the Amazon Lightsail Browser SSH client to connect to the instance.
I Didn’t Follow This Guide. How Do I Fix The Upstream Not Found [519] Error?
Connect to your Lightsail instance using PuTTY and run the following in the terminal:
sudo sed -i -e '/UsePrivilegeSeparation/d' -e '/KeyRegenerationInterval/d' -e '/ServerKeyBits/d' -e '/RSAAuthentication/d' -e '/RhostsRSAAuthentication/d' /etc/ssh/sshd_config && sudo systemctl restart ssh