How do I find XAUTHORITY file through ssh?

Hello. I am logged to my Manjaro KDE machine using graphical session and then I try to login to the same computer through ssh. How do find XAUTHORITY file path of the graphical session, using ssh session? I think few versions back XAUTHORITY was always set to $HOME/.Xauthority, but now it seems to be different every time I login to graphical interface eg. now it is /tmp/xauth_hhuFFe

Why do you need .Xauthority?

I set DISPLAY and XAUTHORITY env vars to copy data to X clipboard (want to use the same clipboard between ssh and GUI sessions)

.Xauthority is where it always is → $HOME/.Xauthority

sddm generates a new UUID on every login - the current id is

ls /tmp/sddm*

Thinking out loud here - are you using wayland or x11 - I don’t think wayland writes .Xauthority - of course I could be wrong …

On my plasma system .Xauthority exist but is unused. Verifed by removing it and restarting the system.

Logging on using X11 doesn’t change anything - the .Xauthority is not in use.

1 Like

I use x11. I just checked and it seems that setting X clipboard requires only DISPLAY env var to be set, not XAUTHORITY so for clipboard alone I probably don’t need it. But during my day I also got errors (in ssh session) like Can't connect to display ":0": b'Invalid MIT-MAGIC-COOKIE-1 key', which went away only when I set proper XAUTHORITY env var (pointing to current /tmp/xauth_* file). I don’t remember what I was doing exactly (I thought only setting X clipboard) but I will pay bigger attention next time.

This sddm id seems unrelated to xauthority:

$ ls /tmp/sddm*
/tmp/sddm-auth-be9e9372-bced-4ccc-ad67-6ee0f76e0898  /tmp/sddm-:0-febKKD
$ ls /tmp/xauth*
/tmp/xauth_IPySiZ

But I think I found my way to get xauth file - I just need to search for first /tmp/xauth_* file that I find :slight_smile:

Thank you.

Those are completely separate sessions, it’s like you telnet to another machine (no matter if the machine you connect to has same IP as the host).
So to use the same clipboard you need to copy-over the clipboard contents…
The two sessions don’t share the same environment and thus don’t have access to same data…

Put differently:
You want another machine to have access to the clipboard on your machine, but that clipboard only exists in the memory of your machine.
Hence you need to transfer it as data over the connection for it to be available on the other side.

:vulcan_salute:


So instead of asking a solution for what you are doing, ask how to do what your end goal is…

If your end goal is to have a shared clipboard between two machines:

  • You need to create a daemon/client connection both ways that synchronize the clipboard on both machines.

So bottom line:
Why are you using ssh in the first place?

1 Like

What is the purpose - the use case - if you like for putting content into another session’s clipboard?

Even if the sessions are owned by the same user - it makes no sense what you are doing.

But clipboard sync has already worked seamlessly for me for long time - until I got problems with XAUTHORITY (or so I thought) lately. For me all 3 clipboards are seamlessly synced: remote ssh <=> remote X <=> local X

Ssh => remote sync is handled by tmux (whenever I copy something in shell, tmux runs xclip to copy it to remote X session, that’s why i need DISPLAY - and I thought XAUTHORITY too, but as i checked today it may not be the case).
Remote X <=> Local X sync is handled by AnyDesk (which I also use to run some graphical apps remotely, which don’t work locally because of network settings and/or permissions).

If you have better workflow for syncing ssh (tmux) <=> remote X <=> Local X let me know :).

Why I need it? I work on my local computer and use cli tools and gui apps to do my job. Some of the cli tools/gui apps work on my local computer and some only on remote host (or I prefer them to run on remote host, which is stronger than my local computer). Sometimes I need to copy things between all 3 places - eg. I open data files using visidata in terminal (ssh remote session), run some analysis, extract some ids from some columns and need to paste the results in GUI app running locally (vscode, or BigQuery editor) and sometimes in remote X session (eg in MongoDB compass or other tools).

I hope I cleared some things why I use different computers/sessions and sync clipboard between them. I’m all ears if you think I can do something better :slight_smile:

Sorry but the scenario you describe there, falls in my book into the category of “Black Hats”, no further help from me, i’ve already said too much… :woman_shrugging:
:vulcan_salute:

ok, thank you for your time, I already know how to find current .Xauthority if i need it :slight_smile:

I was thinking - have you tried ssh with X11Forwarding ?

You would then be able to run both x application and console applications on your local system.

This would keep your clipboard on your local system.

On the remote system - edit the /etc/ssh/sshd_config

Add a section - save the file and restart the daemon

Match User your-usr-name
  X11Forwarding yes

from man ssh_config

       ForwardX11Trusted
               If this option is set to yes, remote X11 clients will have 
               full access to the original X11 display.

               If  this  option  is set to no (the default), remote X11 
               clients will be considered untrusted and prevented from 
               stealing or tampering with data belonging to trusted X11 
               clients.  Furthermore, the xauth(1) token used for the 
               session will be set to expire after 20 minutes.  Remote 
               clients will be refused access after this time.

               See the X11 SECURITY extension specification for full 
               details on the restrictions imposed on untrusted clients.

@kossak

https://wiki.archlinux.org/title/SDDM#X_authority_(aka_MIT-MAGIC-COOKIE)_file

1 Like

Thank you for suggestion. I haven’t tried X11Forwarding for long time (and back then when I tried I wasn’t fully satisfied with it), but I will try again.

Not sure if this alone makes the same clipboard available for CLI tools on remote machine (through ssh) and my local, but we’ll see.