Ubuntu gets stuck in a login loop

My Ubuntu is stuck in a login loop when trying to enter my desktop. When I login, the screen gets black and soon after that the login screen comes back.

I've read that the problem might be caused by an error depending on the graphics, here's my graphics card: ATI Radeon 7670M

20

50 Answers

12

Did you end up here after running sudo startx? Nevertheless:

Press Ctrl+Alt+F3 and login into the shell.

Now run ls -lA. If you see the line

-rw------- 1 root root 53 Nov 29 10:19 .Xauthority

then you need to do chown username:username .Xauthority and try logging in (you may also need to do the same for for .ICEauthority).

Else, do ls -ld /tmp. Check for the first 10 letters in the left: they should read exactly so: drwxrwxrwt.

drwxrwxrwt 15 root root 4096 Nov 30 04:17 /tmp

Else, you need to do sudo chmod a+wt /tmp and check again.

If not both, I'd recommend you either

  1. sudo dpkg-reconfigure lightdm
  2. or uninstall, reinstall it.

Now press Alt+ until you reach the login screen again, and restart.

35

I had this and after looking at /var/log/Xorg.0.log I found out that it's a Nvidia problem (there was a line saying Xlib: extension "GLX" missing on display ":0).

I realized I have Nvidia drivers from official website which are not really stable and tested (so I've read and also experienced in the past).

The solution here was to install package nvidia-current from Ubuntu repos; it is an awfully outdated version, but it's tested properly at least. Its installer is quite capable too and it uninstalled successfully my hack-installed unstable version from Nvidia website.

TL;DR, just try logging into the shell (Ctrl+Alt+F2 or whatever F between F1 and F6) and type

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-367

If it succeeds, reboot.

sudo reboot

If you're lucky enough, problem solved, you should be able to login to Unity.

UPDATE

Please note that sometimes nvidia-current might install the wrong driver. In that case, search the latest compatible driver for your video card and install it. For example, on Ubuntu 16.04, nvidia-current points to the version: 304.131-0ubuntu3. This might be incompatible with your graphics card; therefore, search with sudo apt-cache search nvidia-[0-9]+$ for the package you need, and install it.

12

I encountered this exact problem and none of the suggested fixes above worked for me. After almost giving up I looked at the .xsession-errors and noticed I had a typo in my .profile (I had an extra } in the file after I edited it earlier in the day).

That was causing the login loop. It might be another place to look if the other suggested fixes don't work for you.

13

I had a nearly identical problem a few months ago. Switching into a console from the LightDM login screen (Ctrl-Alt-F1), logging in with administrative username and password, and entering the following commands resolved the issue:

sudo mv ~/.Xauthority ~/.Xauthority.backup
sudo service lightdm restart
3

My home folder was full :-( df -h will give you this answer I had to connect through ssh made some space and worked like a flower

ctrl+alt+F1, login as user, free up some space and restart your X server! mostely sudo service sddm restart

4

Press Ctrl+ALT+F3. You should be given an unix-style login prompt, so enter your username and password there. From there you should be given a shell (a program that allows you to enter commands, sort of like windows' cmd.exe). Enter these commands and press ENTER (or Return) after writing each one (you will have to enter your password when it shows something like [sudo] password for USERNAME. Note that the password will not show when you are typing it!):

sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get -y install fglrx

Then reboot your computer using this command:

sudo reboot

See if this works :)


If this does not work, try going back to the 3rd terminal (Ctrl+ALT+F3), login, and enter this command (pressing ENTER after you have typed it):

sudo apt-get -y install lxdm

This will show a DOS-like dialog after a bit. If lxdm is not selected, select it by using the UP and DOWN arrow keys, and press ENTER to accept that selection. Then reboot using the same command as before (sudo reboot).


If this still doesn't work, go back to the 3rd terminal (ALT+F3), login, and enter this command (same procedure):

sudo apt-get -y install lubuntu-desktop

This will install a much lighter desktop environment which should work for now (should enable you to login and use your computer). Once that is done, reboot (sudo reboot), and when you are confronted with the login page, select the Lubuntu environment instead of Ubuntu.

17

Faced the same problem today.

The cause was a bit strange to me. xubuntu-desktop was removed, so was ubuntu-desktop. LightDM exited with no error message. Tried lxdm and when I tried to login, it popped up a message saying Xubuntu could not be found.

Reinstalled xubuntu-desktop and it's fixed now. Think apt-get autoremove removed the package.

1

You might be having problems with LightDM, the login manager that comes in Ubuntu by default. In 12.04 it used to do the same problem you are describing.

You can install GDM, an alternative login manager, to get around this:

At the login screen, press and hold Ctrl+Alt+F2 to go to the terminal. Don't be afraid! Just log in here with your username and password.

Then, type sudo apt-get install gdm. Let it install and type sudo dpkg-reconfigure gdm and follow the prompts to set it as your login manager.

Press Ctrl+Alt+F7 to get back to the login screen which should now look different. Does logging in work? If it does, your problem is solved!

If it doesn't, go back to the fullscreen terminal (again, Ctrl+Alt+F2) and run sudo dpkg-reconfigure lightdm to set LightDM as you login manager again. Now you know that this is a problem with your graphics drivers for sure.

5

Your desktop environment is failing to start (it sounds like). I would start by tring to log in as a different user.

Ctrl+Alt+F1 then login

sudo adduser testing

Once the user has been added ctrl+alt+f7 and try to log in as testing. If you can log in as testing then your unity/gnome configuration is borked and should be reset. This Question covers it. I prefer to mv ~/.config ~/.config.old.

2

This is not a direct answer to your case but its more of a general solution to login loops.

The problem could be as simple as a wrong command put into the .profile file in the home directory. (Since that file get loaded on logon)

To see if that is really the case, press Ctrl Alt F1, and login. Checking the .xsession-errors file in your home directory

~/.xsession-errors

This should give some clues about some problematic command.

I've pressed Ctrl+Alt+F3 and logged into the shell. Afterwards with this command:

chown username:username .Xauthority 

Where username is my login name, I've solved the problem.

1

Yes I caused a Login Loop on my main Ubuntu 12.10 user and the fix was simple.

Background: Ubuntu 12.10 is installed in VirtualBox running on Windows 7 and uses Unity.

Cause: From the Desktop I Ctrl+Alt+T into terminal mode and then tried to run 'startx' (I was trying to help a friend over the phone late at night...but this was a stupid thing to do). A new blank Unity desktop appeared and everything hung...

Problem:

Forcing VirtualBox to close and then rebooting Ubuntu I got to the login screen but kept looping back to this same screen everytime after entering the password. No errors were displayed. I could login as Guest but I had no Sudo rights and thus no control... However once logged in as Guest I Ctrl+Alt+F3 and got to a terminal login.

I entered my main user name and password and logged in with command mode. Logout took me back to CLI login and Ctrl+Alt+F7 took me back to Guest desktop. So my account still worked. I then added a test user and gave them sudo rights. From the Unity login I could login and logout Test user with no problem. So Unity still worked.

Fix: So my main account was still accessable via CLI and Unity was working for all other accounts. This indicated a configuation problem on my main account. I followed the advice of SiddharthaRT at the top of this post and did chown username:username .Xauthority. This fixed my problem. Thanks !!

2

I only had to change the permissions of my home folder:

sudo chmod 755 /home/<username>

This can be done by logging in, into a terminal, using your username and password in a shell using CtrlAltF1.

2

Proprietary Driver Issues

MoKSB State

I was able to log in to TTY using ctrl+alt+F1, but had no internet access seeing as the driver is proprietary as well.

No Xorg issues were apparent.

I decided to remove the packages when I recieved the MokSB failed message telling me that it could NOT change the secure boot settings. The notable part is that it prompted me for a password even though it failed.

Secure Boot

Caution: Do NOT just blindly remove your drivers!

A good test to see if it is a Proprietary Driver issue is to turn OFF Secure Boot and boot Ubuntu and attempt to login. If logging in works, then you now know what you're issue is.

Broadcom Drivers and Nvidia Drivers

I removed nvidia packages

sudo apt-get purge nvidia-*

and then I removed the broadcom packages

sudo apt-get purge bcmwl-kernel-source

and rebooted.

I attempted to login again and success!

I saw my desktop!

I rebooted again. logged in again and everything was set to default.

  • I rebooted into BIOS

  • turned off secure boot (not recommended, need a better solution)

  • booted up ubuntu using grub

  • logged in and installed the downloaded *.deb file for my wifi driver

  • installed it using Software Center

  • and rebooted.

I followed the same procedure for my nvidia drivers seeing as the default video drivers are awful on my card.

Turning Secure Boot On Again

If I turn on Secure Boot again, I see the same issue. Since the drivers are NOT signed, it's not a true Secure Boot and I get locked out.

Personally, I find this to be a very bogus (and annoying) issue.

Alternative Solution?

The most feasible solution I saw was customizing the kernel seeing as I can't simply leave Secure Boot off and turn it On and then Off when I switch OS's. Again, it's just annoying.

UPDATE on Jan 4 2017

According to this article, the Linux Kernel >= 4.6 now officially supports

GeForce GTX 900 series accelerated support in conjunction with signed firmware images.

This should resolve the secure boot issue caused by using the unsigned firmware images.

3

I have been through this problem multiple times and it has been a different issue each time. One of the following issues could have caused your problem and you could use the command line interface by using Ctrl+Alt+F1 (Replace F1 with F2,F3.... if your tty1 is occupied) to try the following solutions

NVIDIA drivers missing or broken?

  1. Run nvidia-smi to access the NVIDIA system management interface. The output should be something of this sort.
Mon Sep 17 14:58:26 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.87 Driver Version: 390.87 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GT 720 Off | 00000000:01:00.0 N/A | N/A |
| 19% 35C P8 N/A / N/A | 543MiB / 980MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+

If you're not able to access it, there is probably some issue with your graphic drivers.

  1. In that case, you should be able to find out the name of your graphics card using lspci | grep VGA.
  2. You can find out the compatible drivers for your graphics card using the link.
  3. (Try without this stepand maybe then with this step if there was no success). Remove the existing broken drivers using sudo apt-get purge nvidia*.
  4. Install the drivers using

    sudo add-apt-repository ppa:graphics-drivers

    sudo apt-get update

    sudo apt-get install nvidia-390 (Or whatever the compatible driver is for your graphics card)

  5. Try a restart using systemctl reboot -i and hope your login loop is fixed.

Is your HOME your HOME?

  1. Check the owner of your home directory using ls -l /home
  2. If you don not own your home directory, change it using sudo chown $USER:$USER $HOME
  3. Try a restart using systemctl reboot -i and hope your login loop is fixed.

Do you own your .Xauthority?

  1. Check the owner of your home directory using ls -l ~/.Xauthority
  2. If you don't own your .Xauthority, change it using sudo chown $USER:$USER ~/.Xauthority
  3. If you do, move your .Xauthority file using sudo mv ~/.Xauthority ~/.Xauthority.bak
  4. Try a restart using systemctl reboot -i and hope your login loop is fixed.
  5. You might need to do the same thing on .ICEauthority.

Is your /tmp right?

  1. Run ls -ld /tmp and make sure the permissions are exactly drwxrwxrwt. The output should be of this sort

drwxrwxrwt 27 root root 36864 Sep 17 17:15 /tmp

  1. If not, run sudo chmod a+wt /tmp
  2. Try a restart using systemctl reboot -i and hope your login loop is fixed.

Maybe lightdm is your problem?

  1. Reconfigure your display manager using dpkg-reconfigure lightdm and try out other display managers (gdm3,lightdm,) that are available. Maybe this will you give you enough clues to move forward.
  2. If none of them help,try installing sddm using sudo apt-get install sddm for one final try. reconfigure display to sddm.

If none of the above solutions worked, you can try re-installing ubuntu.

P.S: This is a compilation of answers from the sources I refered to, some from this post as well.

sudo chown $USER:$USER $HOME

was the problem for me.

I had set up a home partition with:

sudo mkdir /home/$USER

but forgot to chown it.

1

I got the login loop in connection with an update from Ubuntu 12.04 to 14.04. With gdm I had error messages in ~/.cache/gdm/session.log with entries such as /etc/gdm/Xsession: line 33: mktemp: command not found and after sudo aptitude purge gdm with lightdm I got several similar error messages in ~/.xsession-errors, e.g., usr/sbin/lightdm-session: line 24: mktemp: command not found.

I tried several things. What I believe did eventually resolve the problem for me was this:

I moved my configuration files .profile, .bashrc and .pam_environment to other names and then I managed to login. I suspect that there is a problem in one of them.

1

I found my /tmp file permission settings were not correct. It had permissions for root only.

This was my own mistake. I forgot that a day earlier, I deleted the /tmp folder with sudo rights and after recreated the folder again with sudo mkdir tmp. Big mistake. I created a /tmp folder with root permissions only.

In the ~/.Xsession-errors file I could see that x11 was not able to write a file in /tmp. After execute these commands from the root account (or Alt+Ctrl+f1) in welcome screen and use the problem account credentials to login) I solved the problem:

sudo chmod 1777 /tmp
sudo chown root:root /tmp

After these, I was able to login to Unity again with the normal account again. So if you have, what looks like a .Xauthority problem, you could try this if nothing else works.

See this thread on Ubuntu Forums

I had the same problem after a clean install of Ubuntu 12.10 (but reusing my existing home partition). I tried all of the other answers, but none worked. But I found the clue to my specific problem in the file .xsession-errors in my home directory.

This is how I solved it in my case:

  1. Hit Ctrl+Alt+F1 to open a virtual terminal. Then login with username and password.

  2. Open the file ~/.xsession-errors if it exists (type cat ~/.xsession-errors). In my case, this file contained one single line with an error message:

    /usr/sbin/lightdm-session: 27: .: Can't open /usr/bin/byobu-launch

  3. Now byobu is a command line tool that I use and I have no idea how that ended up in a system file since this was right after a clean install. Byobu is not installed by default, so that might explain the error as it looks for a file (/usr/bin/byobu-launch) that doesn't exist. So in my case I had to install byobu to fix the problem:

    sudo apt-get install byobu

  4. Hit Ctrl+Alt+F7 to go back to the login screen, and login worked fine now.

Of course in your case you might find a different error message in .xsession-errors, which requires a different solution.

I had a very similar issue where I could log in on the terminal but not on the desktop, my wallpaper from the profile was loaded during login, but after a few seconds it jumped back to the login screen. I checked all file permissions as suggested, they were fine. I tried without a separate home partition and was able to log in to the desktop. After that I checked the settings for the LUKS encrypted home partition, which were also fine (though there were some error messages on the terminal, telling me that the encrypted volume could not be mounted, because it was already mounted).

Then I looked into dmesg, found BTRFS errors related to the filesystem on the LUKS encrypted home partition (yep, I'm mixing LUKS and BTRFS), tried to actually write to the filesystem and found that it gave me I/O errors. So I had to repair the filesystem or create a new one and restore from backup.

Long story short: Look at dmesg and actually try to write to the filesystem that seems to be writable.

This could also be because of a special combination of settings:

  • Encrypted /home/$USER
  • $USER in nopasswdlogin group

lightdm will try to log you in, but can't access any files so you get the described symptoms.

To fix this, remove $USER from the group:

sudo gpasswd -d $USER nopasswdlogin

I had to deal with the same problem. Unfortunately in my case it was not resolved by simply changing permissions so my contribution will be to try to create a guide from the simple to the more complex steps. Hopefully your uses will be resolved with the simple ones.

Note: replace <username> with your username.

Assumptions: Nvidia Graphic Card, lightdm


Access To Terminal

To open a new terminal simply use (and then login with your credentials):

Ctrl+Alt+F1

Check the owned/group/permissions of your home directory files

cd ~<username>
ls -lah

Fix the owner and group of .Xauthority and /tmp

chown <username>:<username> .Xauthority
sudo chmod a+wt /tmp

Check if there is still a problem by restarting lightdm

sudo service lightdm restart

Reconfigure lightdm

dpkg-reconfigure lightdm
sudo service lightdm restart

If you wish to see possible errors from the system

tail -n 50 /var/log/Xorg.0.log # if you want to see the last 50 errors
tail -f /var/log/Xorg.0.log # if you want to be able to see all new errors live

Relevant log files:

/var/log/Xorg.0.log
/var/log/lightdm/lightdm.log

As a last resort, which is what I did, reinstall the graphic card drivers.Nvidia simply does not work nice with Ubuntu.

I had to remove NVIDIA drivers to get in, as in (replace nvidia-current with nvidia-340 or whatever your number is).

Revert back to Nouveau drivers

Then I had a buggy UNITY frame. I had to follow the steps showed here to fix them:

1

This happened to me when I switched off the computer while it was still finishing upgrading to the latest kernel images. I did CTRL-ALT F1, logged in, then sudo apt-get update and sudo apt-get dist-upgrade and let it finish to setup.

After rebooting, I was able to login into the destkop again.

I experienced the same problem and the cause in my case was that I tried to add something to the /etc/environment file and whatever I added seemed to not want me to log in after I restarted.

Solution:

When at the login screen press CTRL + ALT + F2. Login with admin username and password and edit the /etc/environment file and remove what changes you made to it.

In the terminal, you can run the following command use nano to edit the file:

sudo nano /etc/environment

Press CTRL + o and then press ENTER to save the file. Press CTRL + x to exit nano.

Once you have edited and saved the file, simply hit CTRL + ALT + F2 to go back to the GUI login screen and you should be able to log on.

20.04 and above:

Opening a console

To open a console, you can press Ctrl + Alt + f5 or boot into grub recovery mode.

Method #1 Removing Old Configuration files.

As System 76 support says in their article, you can remove the old configuration files to fix this issue:

  1. Add a new user
sudo adduser test
  1. log in as the new user (test)

  2. If the login worked without any issues then there are problems with the configuration files of the main user.

  3. Backup/remove the old configuration files:

mv ~/.config ~/.config.old
mv ~/.local ~/.local.old
mv ~/.cache ~/.cache.old
mv ~/.nvidia-settings-rc ~/.nvidia-settings-rc.old
mv ~/.nv ~/.nv.old
sudo reboot
  1. If the configuration files are automatically generated then leave this step:
sudo mkdir ~/.config
sudo mkdir ~/.local
sudo mkdir ~/.cache
sudo mkdir ~/.nv
sudo mkdir ~/.nvidia-settings-rc
sudo reboot

Now try logging in with the regular user.


Method #2 Changing permissions of .Xauthority

  1. Identify the permissions of the file by running (run this in your home directory):
ls -lah | grep -i Xauthority
  1. You should see the file listed with the permissions first, followed by the username and group that own it. If you see “root” listed there, you’ve found the source of the problem.

  2. Give proper permissions:

sudo chown username:username .Xauthority

change "username" with your username.


Removing Gnome shell extensions

Sometimes a corrupted gnome-shell extension can also cause this issue. Removing the extensions will help:

sudo rm -r ~/.local/share/gnome-shell/extensions/*

Resetting gnome

Sometimes, there are problems with configuration files, in that case resetting gnome and its applications will help:

sudo dconf reset -f /

Installing correct Nvidia drivers

  1. First, remove all the Nvidia drivers by running:
sudo apt purge nvidia*
  1. Auto install the recommended drivers:
sudo ubuntu-drivers autoinstall
  1. Install the specific drivers for your device:
ubuntu-drivers devices
# identify the drivers needed
sudo apt install nvidia<version>
  1. Try using system76 drivers (optional):
sudo touch /etc/apt/preferences.d/system76-apt-preferences
echo "Package: *
Pin: release o=LP-PPA-system76-dev-stable
Pin-Priority: 1001
Package: *
Pin: release o=LP-PPA-system76-dev-pre-stable
Pin-Priority: 1001" >> /etc/apt/preferences.d/system76-apt-preferences
sudo apt-add-repository -y ppa:system76-dev/stable
sudo apt-get update
sudo apt install system76-driver-nvidia
sudo apt update && sudo apt full-upgrade 

Disabling AMD Radeon Drivers

On newer versions of Ubuntu AMD, GPU chips are not well supported, so sometimes it is causing the issue. Turning it off would help:

sudo echo blacklist radeon >> /etc/modprobe.d/blacklist.conf
sudo update-initramfs -c -k all
sudo shutdown -r now

Reinstalling display manager

Sometimes the display manager needs some troubleshooting, reinstall it:

sudo apt install --reinstall ubuntu-desktop gdm3 gnome-shell

After that run:

sudo dpkg-reconfigure gdm3

Select the option gdm and press enter.


Changing display managers

You can install a new display manager by the following commands:

sudo apt install lightdm
### If you want sddm
sudo apt install sddm

Then run:

sudo dpkg-reconfigure <display manager name> # example lightdm

Thanks to System76 support, for letting me use some information (method #1, method #3, and method #4) for letting me use some information from their article.

0

Change to another login screen.

Ctrl+Alt+F2 to open a terminal.

Ctrl+Alt+F7 to go back to the graphic mode.

Type sudo dpkg-reconfigure gdm

In a graphic screen, select gdm and OK.

Type sudo reboot

5

Just in case changing the access privileges for the files .Xauthority and .IDEauthority with the chown command did not work for you:

This solution applies to those who besides having had to change access privileges for the above mentioned files cannot use commands as they used to, i.e. the shell does not find the commands. (This is the reason, why the login command cannot be executed either.)

Type echo $SHELL into your terminal. If you get back /bin/bash, use export PATH=$PATH:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin to temporarily be able to use commands.

Then open your .profile file, located in your home directory ~, i.e. /home/yourusername with sudo gedit ~/.profile and add the missing paths to PATH, so that it looks like this:

PATH=/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

Now reboot your system so that the changes to the environmental variable PATH take effect.

(If commands are not recognized by your shell, you could also use the equivalent paths to the executables of the commands, e.g., instead of sudo gedit ~/.profile type /usr/bin/sudo /usr/bin/gedit ~/.profile. The shell tells you the directory to use, i.e. command not found, but the command your are trying to use can be found in /path/to/command's/directory - could be any of the paths you see above.)

1

For me configuration of some packages was off, so running (after ctrl + alt + F3):

sudo dpkg --configure -a

fixed the problem.

1

May you are affected by Bug #1240336 where different permissions are gone after release upgrade.

Other side effects

  • no guest login
  • Synaptic not starting from menu

I get login to work when I put the user into the video group or after running sudo chmod a+rw /dev/dri/* in a terminal.

But:

  • no sound
  • Logout from user menu not working
  • running /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1gives: polkit-gnome-authentication-agent-1:5805): polkit-gnome-1-WARNING **: Unable to determine the session we are in: No session for pid 5805

Solution

Run sudo pam-auth-update --force in terminal. This solved the described problems in my cases.

12

You Might Also Like