Ubuntu: Why do I have so many .Xauthority.* files in my home directory?


I'm using Ubuntu 13.04 on a Lenovo X220.

Why do I have so many .Xauthority.* files in my home directory? I.e

.Xauthority .Xauthority.0JW6UW .Xauthority.2HWRVW .Xauthority.2TA6VW .Xauthority.49F8VW .Xauthority.4E27UW .Xauthority.7CLTVW .Xauthority.8JGGXW .Xauthority.96SAVW .Xauthority.AOUFVW .Xauthority.ASDOVW .Xauthority.CGVJXW .Xauthority.E0ZSVW .Xauthority.E5VZWW .Xauthority.FE64UW .Xauthority.FIHDWW .Xauthority.HL45VW .Xauthority.HYCCVW .Xauthority.ILUEWW .Xauthority.JXJHVW .Xauthority.K1QJXW .Xauthority.KXSOVW .Xauthority.LEKEVW .Xauthority.M48WVW .Xauthority.M6QTVW .Xauthority.MW6NWW .Xauthority.N57TWW .Xauthority.O5HAWW .Xauthority.OIC5VW .Xauthority.P2RPVW .Xauthority.Q0FRVW .Xauthority.QW01WW .Xauthority.RDW5WW .Xauthority.T0TLWW .Xauthority.TSO4WW .Xauthority.U6R9VW .Xauthority.V3KAWW .Xauthority.W8Z1WW .Xauthority.XDLGVW .Xauthority.XOOHWW.Xauthority.XUICVW

They are all zero bytes except the first, with timestamps all over the place.

What are these, and are they safe to delete?


These are the "cookies" of the X client to allow connection to the X server (displays). It's very clearly explained in the wiki:

xauth is a mechanism for enforcing access controls on X servers (displays). When an X server is started, it is given a randomly-generated "cookie". This cookie is written to a file owned and readable by the user whose session the X server is running. No other users can read that file. When an X client (application) is started, it attempts to read and use the cookie to authenticate itself with the server. If this "xauth" authentication fails, the application is not allowed to connect to the server and show windows on the X display.

The command

$ xauth list

will show the cookies available to the current session:

selene/unix:0  MIT-MAGIC-COOKIE-1  c2438e7c2858f142e0b81d6b4fe3867b  localhost.localdomain/unix:0  MIT-MAGIC-COOKIE-1   c2438e7c2858f142e0b81d6b4fe3867b  

Traditionally, the location for each users' cookies has been ~/.Xauthority: the X server writes its cookies to that file as it starts up, and xauth (and other X clients) look in that file for authentication cookies.

Source: https://wiki.ubuntu.com/RemoteXHowTo

And as is shown here, it seems that is a bug of lightdm that doesn't remove the old cookies and pollutes the /home directory.


In fact, I have this problem as you and also with .goutputstream files as is shown in this other bug:


Then yes, you can delete them because if you don't have a cookie to connect to a X server, you are going to create one new.


Seems its a bug that a few people experience with lightdm

So follow this link and when they solve it you will have your answer.


So installing gdm window manager might avoid the issue. As I don't have the problem I cannot test that.


For those -- like me -- wishing to get rid of this "pollution" in the user directory, an interim solution could be placing something like the following (executable) script file (which assumes you are the first user after root) into the /etc/cron.daily directory:

#!/bin/bash  USER="$(users | awk -F ' ' '{print $2}')"  ls /home/"$USER"/.Xauthority.* > /home/"$USER"/.Xauthority-Files.txt  NFILES="$(grep -c Xauthority /home/"$USER"/.Xauthority-Files.txt)"  LOG="/home/"$USER"/.Xauthority-Files.log"  echo -e "$(date +"%x %R"): "$NFILES" .Xauthority.* files deleted" >> "$LOG"  rm -f /home/"$USER"/.Xauthority.*  rm -f /home/"$USER"/.Xauthority-Files.txt  exit 0  

NOTE: This updated script keeps a log file named ".Xauthority-Files.log" so that you can follow up if a recent update has put an end to this bug, and then remove the script when it's no longer needed.


@user196886 suggests an alternative script, saying "I don't want to muck about with the USER variable, I only want the home directories of graphical login users (UID>500), with a home in /home I need privileges to delete other users files, I am happy to see what I am deleting and will confirm manually. My log file is just called Xa.log, $h is a home directory, $b a basename abbreviation to log and delete with."

And the script suggested is:

for h in `awk -F: '$3 >500 && /home/ {print $6}' /etc/passwd`; do b=$h/.Xauthority;[ -f $b.* ] && ls -l $b.* >>Xa.log && sudo rm -i $b.*; done  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »