What is the .Xauthority file?

I had a problem wherein I couldn't get past the login screen in Ubuntu 12.04. Even though I gave the correct username and password, it still came back to the login screen. I found a solution wherein I changed the ownership of the .Xauthority in my home folder.

These are the steps I used:

  1. Ctrl+Alt+F1 when I'm in the login screen.
  2. Change the ownership of .Xauthority which was previously owned by ROOT by executing:

    chown username:username .Xauthority
    

What is this .Xauthority file in the first place? Why does changing the ownership of the file fix my problem of being unable to log in?


The .Xauthority (not .xAuthority) file can be found in each user home directory and is used to store credentials in cookies used by xauth for authentication of X sessions. Once an X session is started, the cookie is used to authenticate connections to that specific display. You can find more info on X authentication and X authority in the xauth man pages (type man xauth in a terminal).

So, if you are not the owner of this file you can't login since you can't store your credentials there.

This situation usually arises when you execute a GUI application (for instance nautilus) with root permissions by typing sudo nautilus. You can avoid it (for 12.10 and older versions) by invoking the app with gksudo nautilus, or in any version using sudo -H nautilus.