Cannot login to ubuntu after startx command

I wanted to manually configure the internet settings & decided to seek help from this website. Ubuntu did not allow me to perform step 1 saying,

X: user not authorized to run the X server, aborting

so I logged in as superuser by executing sudo -s. Then I executed step 1. Suddenly all the tray icons disappeared & the only thing that was being displayed was the wallpaper. I wasn't able to shutdown/restart & chose to shutdown the laptop directly with power button. Upon restart, I had the following problems,

PROBLEMS :

  • I am able to login with a guest account.
  • I'm unable to login with my user account. Logging in brings me back to the login screen.

I am using ubuntu 13.04. How can I fix this?


Solution 1:

To solve the problem:

Open a terminal window Ctrl + Alt + T and type in the commands:

cd ~
sudo chown username:groupname .Xauthority

(replace username and groupname with that of your own, usually your group name will be same as your username.)

Avoid running startx as root:

Since you started X system as root (by logging-in as root and using startx) the file .Xauthority in your user-home directory (~) got owned by the root, and that's the reason why you're stuck with log-in loops. And that's why you shouldn't run sudo startx. You can solve this by giving the ownership of the file back to your user as shown above.

Reference:

  • sudo Vs. gksu/gksudo

Solution 2:

I wanted to add something to precise's answer. I did exactly that but it wasn't enough in my case. If someone still can't log in after following precise's instructions, do this:

ls -l ~/.ICEauthority

If it says something like -rw------- 1 root root 684 may 9 11:56 /home/user/.ICEauthority, do

sudo chown user:user ~/.ICEauthority

where user is, of course, your username.