How to Fix ‘xauth: timeout in locking authority file /home/user/.Xauthority’ in Linux

Logging into a Linux server over SSH with X11 forwarding enabled (ssh -X or ssh -Y) or switching user accounts via su / sudo can frequently trigger an annoying terminal delay followed by the error: /usr/bin/xauth: timeout in locking authority file /home/username/.Xauthority. After stalling for several seconds, the shell session finally opens, but graphical X11 application forwarding fails completely. This warning indicates that the X authentication manager (xauth) is unable to acquire an exclusive lock file on the user’s cookie file, preventing authentication tokens from synchronising.

Why Does xauth Encounter a Lock File Timeout?

The X Window System relies on the ~/.Xauthority file to store magic cookies that authenticate client applications with the X server display. When xauth attempts to write new cookie records, it creates a temporary lock file (.Xauthority-c or .Xauthority-l). The timeout error occurs due to:

  • Orphaned Stale Lock Files: An earlier SSH connection or terminal window closed abruptly, crashed, or was terminated via SIGKILL, leaving behind an unreleased lock file on disk.
  • Full Filesystem (Zero Inodes or Disk Space): If the root filesystem or /home partition is at 100% disk usage, xauth cannot write lock tokens to disk.
  • Incorrect File Ownership and Permissions: The ~/.Xauthority file or the user’s home directory was mistakenly modified to be owned by root (often after running sudo startx or sudo su without environmental isolation).
  • Network File System (NFS) Lock Deadlocks: Home directories hosted across NFS shares experiencing stale file locking daemons (rpc.statd / rpc.lockd).
  • Read-Only Filesystem Mounts: Underlying disk errors forcing the Linux kernel to remount /home in read-only mode to prevent corruption.

Step 1: Remove Stale xauth Lock Files

Deleting orphaned lock files allows xauth to acquire an immediate write lock on the authority container.

  1. Log into your Linux terminal.
  2. Check for the presence of lingering xauth lock files in your home directory:
    ls -la ~/.Xauthority*
  3. If you observe files named .Xauthority-c, .Xauthority-l, or .Xauthority-e, delete them using:
    rm -f ~/.Xauthority-*
  4. Log out of your SSH session:
    exit
  5. Reconnect using ssh -X user@hostname. If stale lock files were the cause, the session connects immediately without delay.

Step 2: Reclaim Home Directory and .Xauthority Ownership

Ensure that the active user account owns the authority file and holds read and write permissions.

  1. Check the file ownership of your authority record:
    ls -l ~/.Xauthority
  2. If the owner is displayed as root or another administrative user, restore ownership to your personal account:
    sudo chown $USER:$USER ~/.Xauthority
    chmod 600 ~/.Xauthority
  3. Also verify that your parent home directory itself is owned by your user and not set to read-only:
    sudo chown $USER:$USER /home/$USER
    chmod 755 /home/$USER

Step 3: Recreate a Fresh .Xauthority File

If the existing file structure is corrupted, generating a fresh authority database resets the token mechanism cleanly.

  1. Back up and remove the damaged file:
    mv ~/.Xauthority ~/.Xauthority.bak
  2. Generate a clean, empty authority file:
    touch ~/.Xauthority
    chmod 600 ~/.Xauthority
  3. Generate a fresh magic cookie using mcookie and merge it into xauth:
    xauth add $(hostname)/unix:0 . $(mcookie)
  4. Verify that the new cookie is registered:
    xauth list

Step 4: Check for Disk Space and Inode Exhaustion

Verify that your storage volume possesses sufficient capacity to create temporary lock files.

  1. Inspect available disk space across all mounted filesystems:
    df -h /home
  2. If usage is at 100%, delete unnecessary temporary files, package caches, or old log files in /var/log.
  3. Next, check inode availability (a disk with free megabytes can still fail if inode allocation is 100% full):
    df -i /home
  4. If inode usage is exhausted, locate and remove directories containing millions of tiny cache files.

Step 5: Resolve NFS Lock Protocol Deadlocks

If your user profile resides on an enterprise NFS network mount, configure local file locking.

  1. Check if your home directory is mounted over NFS:
    mount | grep /home
  2. If mounted via NFS, stale server-side lock daemons can block POSIX file locks.
  3. Add the local_lock=all or nolock option to the NFS mount parameters in /etc/fstab to handle authority locks locally on the client machine.
  4. Alternatively, redirect the XAUTHORITY environment variable to a local non-NFS directory (such as /tmp) by adding the following line to your ~/.bashrc or ~/.zshrc:
    export XAUTHORITY=/tmp/.Xauthority-$USER
  5. Source the updated profile (source ~/.bashrc) to apply the configuration.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.