login loop ubuntu 12.04

Today I restarted Ubuntu 12.04, after installing some packages and having updated firefox. When I came in the login screen, I typed my password. After about one second processing, the screen blacked out and returned to the login screen. It gave no errors (like invalid password).

I read something about lightdm causing this issue, so I tried to install gdm in TTY. When I tried to do this, TTY gave me an 'incorrect password (or login)' error. I am very sure my password was correct and I even tried ticking it in the command section so I could rule out changes in the keyboard layout.

I would be very thankful if someone could help me out of this problem since I am now unable to use Ubuntu and similar questions won't solve my problem (since i can't get in TTY altogether).

Edit: I forgot to tell that 2D login and guest login don't work either. I've tried to use mv ~/.Xauthority ~/.Xauthority.old, which didn't work (the tty didn't give a reaction and it didn't resolve the problem).

I also tried to install gdm (to stop using lightdm) using sudo apt-get install gdm and it responded with:

sudo: /usr/lib/sudo/sudoers.so must be only be writable by owner
sudo: fatal error, unable to load plugins

other than this, I haven't tried anything yet.

Edit(2): I tried the command sudo rm ./.Xauthority, which gave the same error as above. Do I need to reïnstall (or retrieve a backup of) my system or can it be saved?

Edit(3): I solved the sudo problem (thanks Shantanu!). I needed to change ownership of several (sudo-related) files. I used pkexec to change ownership using the terminal. I now realize that this shift in ownership may be the cause of my loginloop problem. sudo does work now, so I'll try some other commands. I would be thankful if someone can offer me help on this matter!


Solution 1:

I had a similar problem running Kubuntu 12.04 for a long time: The login screen appeared as normal, but logging in would not take me to a plasma desktop, but rather back to the login screen. I assume the problem works about the same way for Ubuntu with gdm as it did for me using kdm.

As a temporary solution, I was able to get to a proper desktop environment by entering:

sudo service kdm stop
startx

from a tty console, which I escaped to with ctrl+alt+f3 from the login screen.

Suspecting a permissions issue with .Xauthority and or my /tmp/ directory (as per many other answers to this same question), I ran:

ls -la ~/.Xauthority

and verified its owners were set to username username and not root root, and ran

ls -ld /tmp

and ensured its permissions read as drwxrwxrwt. I also tried removing the .Xauthority file altogether, hoping it would be regenerated properly upon next login, but this didn't work for me (others seem to have had success trying this, however).

Next I checked my ~/.profile for extraneous lines, and read through my .xsession-errors file for clues to no avail.

What eventually worked for me was removing my ~/.dmrc file.

From https://help.ubuntu.com/community/dmrcErrors:

"The .dmrc is an initialization file which the system checks during session login. Specifically, gnome checks the file for any specific language or session information it hasn't located elsewhere. While often the file is blank except for the basic header data, it may contain a specific language to use at session startup."

This file must have 644 permissions to work properly (EDIT: The above link actually gives a few other permissions that will work besides 644, but 644 is the explicitly given permission to set), so before removing it verify that

ls -la ~/.dmrc

yields the permissions drwxr-xr-x 143 user user, and if not try using

chmod 644 /home/username/.dmrc

If none of the above solutions worked, try backing up and removing this file with:

cp /home/username/.dmrc /home/username/.dmrc.backup
rm /home/username/.dmrc

Upon next login, a new .dmrc file will be generated and configured correctly, and in my case I was finally able to log in properly without escaping to tty, killing kdm, and starting x manually.

NOTE: I suspect the root cause of this came when the partition my home folder was on filled up during a session, which caused a whole slew of other issues with configuration files not being written that needed to be written. The infinite login loop problem started immediately after that, and I noticed that the .dmrc file had a size of 0, rather than containing:

[Desktop]
Session=default

as it does now in the fully functioning condition. It seems from the above quote that this file is read on login, and maybe my login loop occurred because Kubuntu didn't know how to handle an empty .dmrc file, but I'm only speculating.

Solution 2:

The answer on this (similar) question solved my problem: Ubuntu gets stuck in a login loop. (the sudo chmod a+wt /tmp code)

However I now have a problem with my color scheme (the colors seem unaligned), but I'll post this in another question since it isn't very related to this problem.

Thanks for all the help!