A few things can throw you into a panic faster than trying to log into your computer and being denied entry. You click on your username, enter your password, hit Enter, and… nothing.

Unfortunately, this kind of experience is more common than you might think with Ubuntu. This is commonly known as the Ubuntu login loop issue; fret not, for it's not difficult to fix this problem, especially when you know what to do.

If your Ubuntu system is stuck in a login loop, follow along, and you will be up and running in no time.

Get to a Terminal From the Ubuntu Login Screen

Is your Ubuntu installation stuck at the login screen? If yes, then the first thing you need to do is drop out of the graphical login screen and fire up the terminal. To do this, boot your system normally and wait for the login screen to appear. From the login screen, press Ctrl + Alt + F3.

Some laptops use the function keys for setting screen brightness or sound volume. On such machines, you may need to hold down another key to have your F3 key act as a function key, not as a volume control or whatever else it might do.

Dell laptops, for example, have a key labeled Fn. On these machines, you need to press Fn + Ctrl + Alt + F3 simultaneously.

Ubuntu TTY login

Pressing this key combination will take you to a terminal screen with a login prompt. Log in with your username and password, and you will be at a command prompt in your home directory. You can enter commands here just as you would in the terminal app from your desktop.

It's best to try the following possibilities to resolve the Ubuntu login loop issue:

1. Check Ownership Settings for Configuration Files

One of the most common reasons behind the Ubuntu login loop is incorrect file ownership settings on one or two of the files that help control the login screen on some systems. They exist as hidden files in your home directory.

Enter the following at the command line to get a full directory listing:

        ls -la
    

Near the end of the listing, look for a file named .Xauthority. This file may not exist on your system. If there's no file with the name .Xauthority, skip to the next suggestion.

Ubuntu TTY Home Directory

If the .Xauthority file does exist, look at the owner and group for the file. These two attributes appear to the left of the file name and size.

In the image above, they are highlighted and both set to root. If this file is on your system and shows as owned by root, this will be your problem. You should own the file, not the root user.

To change the owner settings, enter the following command:

        sudo chown username:username .Xauthority
    

You should, of course, enter the command and substitute "username" with your actual username. Be sure to enter the command exactly as shown. Note the colon between the usernames, the dot at the beginning of the filename, and the capital X.

When done, list the directory again, and the file owner should now be your username.

If the .Xauthority file is set correctly, look further up the directory listing to see if a file named .ICEauthority exists. If you see this file, check its owner as well. If the owner is set to root (or any name other than your username), use the command above to correct the ownership settings; change .Xauthority to .ICEauthority in the aforementioned command.

2. Check Permission Settings on the /tmp Directory

If your Ubuntu's stuck at the login screen, then it could be due to the incorrect permission settings on the system’s /tmp directory. This directory holds all temporary files and can wreak havoc when system processes can’t get to their files.

Ubuntu TTY Root Directory

To see the permissions on the /tmp directory, enter the following two commands:

        cd /
ls -la

The /tmp directory should appear near the end of the list. Here, you want to look at the string of letters in the leftmost column of the directory listing. They represent the permissions for the directory.

In the case of /tmp, that string of letters should be precisely drwxrwxrwt. If your directory listing shows anything different, run the following command to change the file permissions:

        sudo chmod 1777 /tmp
    

3. Check Available Free Space

Another common cause of unexpected Ubuntu loop login issues is limited space on your hard drive. Your system will do strange things when it can’t write to the hard drive.

To check how much free space you have, use the df command:

        df -h ~
    

This will show you how much space you have used and is available on the drive that holds your home directory. If the free space is less than three or four gigabytes, you should look for files to delete. Your downloads directory is probably a good place to start.

You can also use the following command to list disk usage for the entire system:

        df -h
    

If the results of this command show that any device has no free space left, you’ll have to figure out how to remove some files from that device or increase the partition size to open up more space.

You should be extremely careful when removing files outside your home directory or modifying disk partitions. Mistakes could mean losing all of your data.

4. Remove and Reinstall Your Desktop Environment

If all else fails, you can try removing and reinstalling the Ubuntu desktop environment (including GDM) as a last resort. It may take some time to complete, but you only need to enter a few commands.

To perform a fresh install of the desktop, enter the following commands in order:

        sudo apt remove ubuntu-desktop
sudo apt update
sudo apt dist-upgrade
sudo apt autoremove
sudo apt clean
sudo apt install ubuntu-desktop

These commands will remove the current desktop, update the software list, upgrade your system and packages to the latest versions, remove and clean any unused files, and re-install the desktop environment.

Reboot Your System After Each Configuration

After implementing the above-stated solutions, you should reboot your system and try to log in again. To do so, enter the following at the terminal prompt:

        sudo shutdown -r now
    

At this point, you should have broken the Ubuntu login loop issue and gained access to your system again. Although going through this experience is not pleasant for anyone, an important lesson must be learned. Things like this are precisely why making regular backups of your Linux system is essential.

Sometimes there is no other solution than formatting your drive and starting over. It will be painful if you find yourself in that situation without a backup.