\n
rsync -a –progress \/home\/your_username \/path_to_backup_location\/home_backup<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nNext, back up your system configuration files:<\/p>\n\n\n\n
\n
sudo rsync -a –progress \/etc \/path_to_backup_location\/etc_backup<\/p>\n<\/div><\/div>\n\n\n\n
To re-create your software environment, you can generate a list of all installed packages:<\/p>\n\n\n\n
\n
dpkg –get-selections > \/path_to_backup_location\/package_list.txt<\/p>\n<\/div><\/div>\n\n\n\n
This way we can have information about all packages that are installed and we can reinstall them later if needed:<\/p>\n\n\n\n
\n
sudo dpkg –set-selections < package_list.txt sudo apt-get dselect-upgrade<\/p>\n<\/div><\/div>\n\n\n\n
Step 2: Upgrade All the System Packages<\/h2>\n\n\n\n Upgrading all packages ensures that all software on your system is compatible with newer versions. This compatibility is crucial during a system upgrade because new versions of the operating system may depend on newer versions of libraries and other software packages. If older versions remain, they might not work properly with the new OS version, potentially leading to errors or even failure. Regular updates can often include various security patches and fixes that will close any vulnerabilities in the system.<\/p>\n\n\n\n
Next, we can refresh and update the local package index and upgrade the packages:<\/p>\n\n\n\n
\n
sudo apt update && sudo apt upgrade -y<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nNow it’s a good idea to reboot your system to start using the latest kernel version. You can do so by running the following command:<\/p>\n\n\n\n
\n
sudo reboot<\/p>\n<\/div><\/div>\n\n\n\n
Step 3: Prepare TCP Port 1022<\/h2>\n\n\n\n <\/p><\/div>
Note:<\/strong> It\u2019s a security best practice to use a bastion host whenever possible to avoid expanding your attack surface.<\/p><\/div><\/div><\/div>\n\n\n\nThe default port for SSH connections is port 22. In scenarios where the SSH configuration is altered or incorrectly set during an upgrade, the default SSH service might become inaccessible. Having port 1022 set up as a secondary SSH port ensures that you can still access your system remotely to troubleshoot and fix issues that may have occurred on the default port.<\/p>\n\n\n\n
During the upgrade process, various services and configurations may be restarted or reloaded, including the SSH daemon. If something goes wrong during these operations, having an additional port configured can help to avoid losing remote access to the server.<\/p>\n\n\n\n
We can start by allowing this specific port in our Ubuntu firewall:<\/p>\n\n\n\n
\n
sudo ufw allow 1022\/tcp<\/p>\n<\/div><\/div>\n\n\n\n
To apply the rule run the following command:<\/p>\n\n\n\n
\n
sudo ufw reload<\/p>\n<\/div><\/div>\n\n\n\n
Finally, we can check whether ports are listed properly:<\/p>\n\n\n\n
\n
sudo ufw status<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nStep 4: Upgrade from Ubuntu 22.04 LTS to Ubuntu 24.04 LTS Version<\/h2>\n\n\n\n We are now ready to upgrade to the latest Ubuntu LTS version. We can update either via GUI or through the command line.<\/p>\n\n\n\n
In this tutorial, we will use the do-release-upgrade<\/strong> tool through the command line.<\/p>\n\n\n\nIf the tool is not installed already, we can install it by running the following command:<\/p>\n\n\n\n
\n
sudo apt-get install ubuntu-release-upgrader-core<\/p>\n<\/div><\/div>\n\n\n\n
In our case, it was already installed:<\/p>\n\n\n\n <\/figure>\n\n\n\nNext, we can launch the upgrade tool:<\/p>\n\n\n\n
\n
sudo do-release-upgrade -d<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nSimply respond with ‘y’ <\/strong>on the first prompt to continue.<\/p>\n\n\n\nNow we will receive another prompt that an additional ssh daemon will be started at port 1022, which we configured previously.<\/p>\n\n\n\n
So here, just enter ‘y’ <\/strong>again and continue with the process.<\/p>\n\n\n\n <\/figure>\n\n\n\nNext, we will get a prompt where we will be asked to update the ‘sources.list<\/strong>‘ file for the newest version, so we can continue with the ‘y’ <\/strong>option here and press Enter.<\/p>\n\n\n\nNow we will get the prompt where we get the following information:<\/p>\n\n\n\n
\nThe number of packages that are no longer supported by Canonical.<\/li>\n\n\n\n The number of packages that will be removed, installed, or upgraded.<\/li>\n\n\n\n Download size, estimated duration, and the information on how long it will take for the full upgrade.<\/li>\n<\/ul>\n\n\n\nSo here we can again type ‘y’ <\/strong>and then press Enter.<\/p>\n\n\n\nIn the upgrade process, there might be a couple of prompts that will ask about changing potential versions:<\/p>\n\n\n\n <\/figure>\n\n\n\nChoosing “keep the local version currently installed<\/strong>” means that your existing configuration file (sshd_config in this case) will be preserved. This is often the preferred option if you’ve made custom configurations that you do not want to overwrite, such as specific SSH settings, port numbers, or security settings.<\/p>\n\n\n\nSelecting “install the package maintainer’s version<\/strong>” would replace your sshd_config with the default version from the new package. This could be useful if you want to start fresh with the new default settings or if you’re not concerned about maintaining custom settings.<\/p>\n\n\n\nIf you’re unsure, it’s usually safe to keep the current version, especially if the system is functioning as expected. <\/p>\n\n\n\n
Last, we will get a prompt that states our system upgrade is complete and a restart is required. So we will once again type ‘y’<\/strong> and press Enter to finish the upgrade.<\/p>\n\n\n\n <\/figure>\n\n\n\nStep 5: Verify Proper Upgrade to Ubuntu 24.04 LTS<\/h2>\n\n\n\n Once we log back into the system, we can confirm whether the upgrade was successful if we run the following command:<\/p>\n\n\n\n
\n
lsb_release -a<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nWe can also check the kernel version:<\/p>\n\n\n\n <\/figure>\n\n\n\nStep 6: Remove the Firewall Rule<\/h2>\n\n\n\n Since we have completed the upgrade to the latest version, we can remove the firewall rule for port 1022. We are mainly doing this because we want to keep our system secure, as leaving unattended ports can lead to various vulnerabilities.<\/p>\n\n\n\n
\n
sudo ufw delete allow 1022\/tcp<\/p>\n<\/div><\/div>\n\n\n\n
Step 7: Enable Third-Party Repositories<\/h2>\n\n\n\n Once we have upgraded our system to the latest version we can enable the third-party repositories that were disabled during the upgrade process.<\/p>\n\n\n\n
We can see these repositories by running the following command:<\/p>\n\n\n\n
\n
ls -l \/etc\/apt\/sources.list.d\/<\/p>\n<\/div><\/div>\n\n\n\n
We can enable it again if we uncomment and remove the # sign at the beginning of each line for each repository, and for that purpose we can use any text editor such as Vim or Nano.<\/p>\n\n\n\n
At the end of our post-upgrade process, we can remove the unnecessary packages with the following command:<\/p>\n\n\n\n