How to Fix the Ubuntu Login Loop

Written by
Ubuntu Linux start up screen on a laptop
Jordan Gloor / How-To Geek
If you’re trapped in a login loop on Ubuntu Linux, use Ctrl+Alt+F3 to open a terminal and check or remove the .Xauthority file. If that doesn’t work, making sure root owns the /tmp folder, reconfiguring gdm3, and freeing up hard drive space can also break you out of the loop.

The Ubuntu login loop is a frustrating problem that makes it impossible for you to log in. We describe six different issues that can cause this behavior and how to fix them.

Table of Contents

What Is a Login Loop on Ubuntu?
Check Ownership of the .Xauthority File
Remove the .Xauthority File
Check the Permissions on the /tmp Directory
Reconfiguring gdm3
Reinstalling gdm3
Checking Hard Drive Free Space
Breaking Out of the Loop

What Is a Login Loop on Ubuntu?

The Ubuntu login loop is a problem that returns you to the login screen instead of logging you in and presenting you with your desktop. It’s as if your credentials are being rejected, but that’s not the case. It’s just not letting you in. Even though you’re definitely typing in the correct user name and password, you’re bounced right back to the login screen.

Of all the possible problems with a computer, not being able to log in is one of the scariest. If you can’t get in, how can you fix it? Thankfully, Linux provides us with more than one way to log in, and we can leverage that to our advantage in this scenario.

Actually, this problem can happen to other distributions as well. It seems to have been tagged the “Ubuntu login loop” because there’s an impression that it’s reported on computers running Ubuntu more frequently than on other distributions. I suspect that’s because there’s more computers running Ubuntu Linux than any other distribution.

RELATED: What’s New in Ubuntu 23.04 “Lunar Lobster”, Available Now

Check Ownership of the .Xauthority File

This fix is only for people who’ve opted to run Ubuntu using Xorg, rather than on Wayland, the new display server. A display server handles screen drawing functionality. Applications talk to the display server, and the display server writes to the screen. It’s used to construct what you see in a graphical desktop environment.

Xorg was replaced by Wayland as the default display server, but you can still log in to Ubuntu using the Xorg server if you want to or need to. Some older applications work better with Xorg than they yet do with Wayland.

To log in to Ubuntu using Xorg, click the cogged wheel icon on the login screen, and select “Ubuntu on Xorg” from the menu.

Choosing to use ubuntu on Wayland or Xorg, from the log in screen options menu

This setting will persist across reboots. To go back to using Wayland, you’ll need to manually change this setting back to “Ubuntu.”

So, if you’ve been using Xorg and find yourself in the login loop, the first thing to check is the ownership of the “.Xauthority” file—if you have one. If you don’t, skip this and the next sections.

At the login screen, press “Ctrl+Alt+F3” to open a terminal screen.

A terminal screen login prompt

Log in with your usual username and password.

Ubuntu login messages on a terminal screen

If you have one, your “.Xauthority” file is a hidden file found in your home directory. We’ll look for one with the -a (all) option, so that ls lists hidden files.

ls -ahl .X*

Using ls to search for an .Xauthority file

On this computer the file is present, but it should be owned by the current user, not by root. But that’s a simple fix. We’ll use the chown command to set ourselves as the owner. You’d substitute your own user name in the command, of course.

sudo chown dave:dave .Xauthority

Changing the ownership of the .Xauthority file

Checking with ls shows we’re the owner and group owner of the file.

If you have a file called “.ICEauthority”, make sure you’re the owner of that file too. We didn’t have one on our test computer. The format of the chown command is the same:

sudo chown dave:dave .ICEauthority

Reboot by typing “reboot” and pressing Enter, and attempt to log in when your system’s back up.

RELATED: How to Use the chown Command on Linux

Remove the .Xauthority File

If taking ownership of the “.Xauthority” file didn’t work, try removing it and recreating it.

At the log in screen, open a terminal window with “Ctrl+Alt+F3”, and use the rm command to delete the file.

rm .Xauthority

Using rm to delete the .Xauthority file

Using the startx command to try to start an X desktop session forces a new “.Xauthority” file to be created.


Using startx to launch an Xorg session

Reboot and try to log in.

Check the Permissions on the /tmp Directory

Many processes use the “/tmp” directory to store temporary files. If the permissions on the “/tmp” directory are messed up and become more restrictive than they need to be, those processes will be adversely affected.

To check this, we need to open a terminal screen, and use ls on the “/tmp” directory. So press Ctrl+Alt+F3 at the login screen, and log in with your usual credentials.

The “/tmp” directory should be owned by root. The root user, the members of the root group, and all other users need to have read, write, and execute permissions in that directory. The only restriction is that people in the others group—which in this case, is everyone but root and processes owned by root—can only change (write and delete) files that they have created themselves.

cd /
ls -ahld tmp

Checking the permissions on the /tmp directory

We can see the permissions string for “/tmp” is drwxrwxrwt and its owner and group owner are both “root.”

The permissions mean:

  • d: This is a directory
  • rwx: The owner has read, write, and execute permissions.
  • rwx: The group owner has read, write, and execute permissions.
  • rwt: Everybody else can read, write, and execute files, but they can only write to or delete files they have created themselves. The “t” is known as a “sticky bit.”

If you see anything other than this, use the chmod command to set these permissions:

sudo chmod 1777 /tmp
ls -ahld tmp

Using chmod to set the permissions on the /tmp directory

As before, reboot and try to log in.

RELATED: How to Use SUID, SGID, and Sticky Bits on Linux

Reconfiguring gdm3

Ubuntu uses gdm3 as its display manager. A display manager handles graphical login screens and graphical display servers. Sometimes forcing a refresh on gdm3 can cure the login loop problem.

Again, at the login screen, open a terminal window with “Ctrl+Alt+F3.”

We’re using the dpkg-reconfigure command to refresh gdm3. It ensures all required files are present and dependencies are met. It should leave gdm3 in the same state as if it had just been successfully installed.

sudo dpkg-reconfigure gdm3

Reconfiguring the gdm3 package

Reboot, log in, and see if your issue has been solved.

Reinstalling gdm3

This process purges gdm3 from your computer and re-installs it. It’s the long-handed way of doing the previous step. I’ve seen the previous step work many times, but if it doesn’t, this usually does.

sudo apt purge gdm3
sudo apt install gdm3

Uninstalling the gdm3 display manager

Give your computer a reboot, and see if you’ve fixed your problem.

Checking Hard Drive Free Space

Running out of hard drive space has a similar effect as not being able to create temporary files. Even with the correct permissions on “/tmp”, if you have no hard drive space left, the system cannot create files.

How to View Free Disk Space and Disk Usage From the Linux Terminal

RELATEDHow to View Free Disk Space and Disk Usage From the Linux Terminal

From the login screen, open a terminal screen as before. we can use df to check on hard drive capacity and free space, and we can use du to see what is taking up the space. Our test machine had no issues with free space, but this is what the output from the commands will look like.

Using the -h (human readable) option forces df to use the most appropriate units for the figures it needs to display. It’s easier than trying to work in bytes.

df -h

Checking hard drive capacities and usage with df

The “Use%” column shows the amount of space used, expressed as a percentage. The “Used” and “Available” columns are expressed in actual values.

The root file system is mounted on “/dev/sda”, and 84 percent of the capacity of the drive has been used. That’s nothing to worry about, but if we were investigating a hard drive that was showing very little space left, we could use du to discover what was taking up the space.

We’re going to use the -h (human readable) and -s (summary) options with du , and we’re piping the output into sort . The options we’re using with sort are -h (sort human-readable values) and -r (reverse sort).

This will give us a sorted, descending list with the largest consumers of hard drive storage at the top of the list.

du -hs * | sort -hr

Generating a sorted list of consumers of hard drive storage

We can see that the “Pictures” directory is by far the largest culprit. We can enhance our du command to look into the “Pictures” directory. We’re also piping it through head to show us the 5 worst offenders.

du -hs ~/Pictures/* | sort -hr | head -5

The five biggest directories in the /Pictures directory

This type of iterative probing allows us to identify the low-hanging fruit. Copying the biggest directories to other internal drives or to external storage, and then deleting them from our home directory, will free up the most hard drive space.

Once you’ve done that—with whatever the biggest directories on your computer happen to be—your system should let you log in.

Breaking Out of the Loop

The Ubuntu login loop is like being locked out of your own home. You’ve got the right key, but the door still won’t open. Thankfully, with Linux there are other doors we can use. And once we’re in, we can try to figure out what’s stopping the front door from working.

RELATED: How to Use GRUB Rescue to Fix Linux

Article Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *