Quick Links
Summary
If you’re trapped in a login loop on Ubuntu Linux, use Ctrl+Alt+F3 to open a terminal and check or remove the.Xauthorityfile. If that doesn’t work, making sure root owns the/tmpfolder, reconfiguringgdm3, 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.
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’re able to’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 usingXorg, rather than onWayland, 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.
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.
Log in with your usualusername and password.
If you have one, your “.Xauthority” file is ahidden filefound in your home directory. We’ll look for one with the-a(all) option, so thatlslists hidden files.
On this computer the file is present, but it should be owned by the current user, not byroot. But that’s a simple fix. We’ll usethechowncommandto set ourselves as the owner. You’d substitute your own user name in the command, of course.
Checking withlsshows 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 thechowncommand is the same:
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 usethermcommandto delete the file.
Using thestartxcommand to try to start an X desktop session forces a new “.Xauthority” file to be created.
Reboot and attempt to log in.
Check the Permissions on the /tmp Directory
Many processes use the “/tmp” directory to store temporary files. If thepermissionson 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 uselson 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.
We can see the permissions string for “/tmp” isdrwxrwxrwtand its owner and group owner are both “root.”
The permissions mean:
If you see anything other than this, usethechmodcommandto set these permissions:
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 thedpkg-reconfigurecommand 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.
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.
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.
Related:How to View Free Disk Space and Disk Usage From the Linux Terminal
From the login screen, open a terminal screen as before. we can usedfto check on hard drive capacity and free space, and we can useduto 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 forcesdfto use the most appropriate units for the figures it needs to display. It’s easier than trying to work in bytes.
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 useduto discover what was taking up the space.
We’re going to use the-h(human readable) and-s(summary) options withdu, and we’re piping the output intosort. The options we’re using withsortare-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.
We can see that the “Pictures” directory is by far the largest culprit. We can enhance ourducommand to look into the “Pictures” directory. We’re also piping it throughheadto show us the 5 worst offenders.
This type of iterative probing allows us to identify the low-hanging fruit.Copying the biggest directoriesto other internal drives or toexternal storage, and thendeletingthem 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.