On some rare occasions, after an upgrade; due to compatibility issues between hardware/software components, when trying to logging you might only see a nasty black screen, or the OS will bring you back to the logins screen; meaning that you are not able to log in at all into Ubuntu.
In most cases, the solution requires direct access to shell and manually make some adjustments.
Open shell view
You can boot on shell root (no need to login) or press CTRL+ALT+F5 to switch to shell view.
Create a test account for discarding configuration issues.
Creating a temporary account will help to discard any configuration issue in the home directory. The following commands will create a new temporary account for testing purposes:
sudo adduser temporary
sudo systemctl reboot
If you are not able to log in with the new temporary account it means that the issue is within your original account’s home folder; so for this reason, the old configuration files need to be deleted in order to allow a normal login:
rm -rf ~/.config
rm -rf ~/.local
rm -rf ~/.cache
rm -rf ~/.nvidia-settings-rc
rm ~/.nv
sudo systemctl reboot
If after rebooting the issue persists, please go back to shell view and continue troubleshooting.
Reinstall the login manager
After an upgrade, some core UI related components might be causing a conflict, so it is recommended to reinstall the GNOME Display Manager and the desktop environment by running the following commands:
sudo apt install –reinstall gdm3 ubuntu-desktop gnome-shell
sudo systemctl reboot
If after rebooting the issue persists, please go back to shell view and continue troubleshooting.
Reinstall NVIDIA Driver
A recent NVIDIA update might also be causing the login issues, so for this reason it would need to be reinstalled. To remove the NVIDIA driver, run the following commands:
sudo apt purge ~nnvidia
sudo apt autoremove
sudo apt clean
After the NVIDIA driver has been removed, reinstall it by executing the following commands:
sudo apt update
sudo apt full-upgrade
sudo ubuntu-drivers autoinstall
sudo systemctl reboot
In most cases, after following these steps, Ubuntu should be able to normally log into Ubuntu; if the problem persists you might need to consider to re-install your OS or look more deeply into any hardware issue.