I would like to generate a new Xauthority file using xauth with another hostname portion and write it to a different file name (as opposed to ~/.Xauthority where the xauth command typically writes to).

[Later on I want to copy this file to another machine with a different hostname. This machine is a container which binds the X socket but does not have the xauth command installed.]

UPDATE: xauth extract ~/.newXauthority $DISPLAY does almost what I want except it does not alter the hostname portion.

I did not find anything useful in xauth's man page.

  • @steeldriver: I think you were correct with the -f option, please excuse my wrong statement. – MCH Apr 24 '16 at 18:11

There are 2 sorts of hostname entries managed by xauth, local names such as myhost/unix:0 and remote names such as remote:0. The latter are held as ip addresses, but I imagine you are referring to the local names.

The hostname part of these are not actually of any significance to X11, but can be used by the xdm tools to distinguish between several local name entries, each with different keys. To change this name simply list the entry you want, take the key at the end of the line, and provide it to the add command with your new hostname:

xauth -f ~/.newXauthority add newhostname/unix:0 . $(xauth list "$DISPLAY" |awk '{print $NF}')

This assumes DISPLAY is :0, and you want the same local display number on the new machine.

  • Thank you, this is exactly what I needed and a great explanation :) – MCH Apr 24 '16 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.