67

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?

Zanna
  • 69,223
  • 56
  • 216
  • 327
chanHXC
  • 1,013
  • 2
  • 10
  • 15
  • sudo -H nautilus does not work with 17.10. Wish there was a real answer how to create .Xauthority when none exists. – vidiman Feb 09 '18 at 05:16
  • [Why don't gksu/gksudo or launching a graphical application with sudo work with Wayland?](https://askubuntu.com/q/961967/158442) – muru Feb 09 '18 at 05:46

1 Answers1

75

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.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
  • thanks for the explanation. Much appreciated. if i'm not mistaken gksudo is much preferred for invoking a command which probably opens a program which requires a graphical interface. In what way that executing sudo instead of gksudo do bad in your system? – chanHXC May 27 '13 at 23:32
  • yes thanks again. I have already marked the answer. :) – chanHXC May 29 '13 at 05:54
  • 1
    This clued me into getting x11vnc going with openSUSE Leap (which I'm using instead of Bionic because of VGA driver issues). Trying to test x11vnc, I couldn't get `sudo x11vnc -forever -rfbauth /home/myusername/.vnc/passwd` to work. but taking away the `sudo` made it work! Haven't tried getting it to make me a sandwich yet. – Will Matheson Feb 19 '20 at 18:42