3

When logged in to the desktop:

$ env | grep XDG_
XDG_CONFIG_DIRS=/etc/xdg
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session4
XDG_MENU_PREFIX=xfce-
XDG_SEAT=seat0
XDG_SESSION_DESKTOP=xfce
XDG_SESSION_TYPE=x11
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/mattd
XDG_CURRENT_DESKTOP=XFCE
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_CLASS=user
XDG_VTNR=1
XDG_SESSION_ID=12
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/usr/local/share:/usr/share

When logged in through SSH:

$ env | grep -i xdg
XDG_SESSION_TYPE=tty
XDG_SESSION_CLASS=user
XDG_SESSION_ID=16
XDG_RUNTIME_DIR=/run/user/1000

Why is my environment different when logged in through SSH?

I am running Fedora 30.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Zhro
  • 2,495
  • 4
  • 28
  • 45

3 Answers3

5

When you’re logged in to the desktop, your desktop environment sets most of those XDG variables.

When you’re logged in via SSH, the only variables you see are those set by pam_systemd: XDG_SESSION_ID, XDG_RUNTIME_DIR, XDG_SESSION_TYPE, XDG_SESSION_CLASS; since there’s no desktop environment, you don’t get XDG_SESSION_DESKTOP, and seat information isn’t set for an SSH connection.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
0

Read man ssh, you want the -X or -Y option

waltinator
  • 4,439
  • 1
  • 16
  • 21
  • I am already using X Forwarding with `-Y`. – Zhro Aug 24 '19 at 01:18
  • `-X` and `-Y` "forward" X Window requests back to the X Window server on the originator of the `ssh` connection. Check the X server logs there. – waltinator Aug 24 '19 at 04:40
  • X Forwarding works fine. The problem is that the `XDG_` environment variables are undefined when logged in through SSH. – Zhro Aug 24 '19 at 04:42
0

After reading man ssh_config and man sshd_config I found that the evnironment variables exported by ssh are controlled by the SendEnv directive in /etc/ssh/ssh_config:

SendEnv
         Specifies what variables from the local environ(7) should be sent to the server.
         The server must also support it, and the server must be configured to accept these
         environment variables.  Note that the TERM environment variable is always sent
         whenever a pseudo-terminal is requested as it is required by the protocol.  Refer to
         AcceptEnv in sshd_config(5) for how to configure the server.  Variables are
         specified by name, which may contain wildcard characters.  Multiple environment
         variables may be separated by whitespace or spread across multiple SendEnv
         directives.  The default is not to send any environment variables.

and, on the server, the AcceptEnv directive in (the server's) /etc/ssh/sshd_config:

 AcceptEnv
         Specifies what environment variables sent by the client will be copied into the
         session's environ(7).  See SendEnv in ssh_config(5) for how to configure the client.
         The TERM environment variable is always sent whenever the client requests a pseudo-
         terminal as it is required by the protocol.  Variables are specified by name, which
         may contain the wildcard characters ‘*’ and ‘?’.  Multiple environment variables may
         be separated by whitespace or spread across multiple AcceptEnv directives.  Be
         warned that some environment variables could be used to bypass restricted user
         environments.  For this reason, care should be taken in the use of this directive.
         The default is not to accept any environment variables.

BUT your XDG_ variables refer to Your desktop session. Simply copying them as-is to another system makes no sense.

This seems like an "XY" problem. Why do you care about XDG_ variables on the server side of he ssh conversation? -X and -Y set up a local X server, and set $DISPLAY for you.

waltinator
  • 4,439
  • 1
  • 16
  • 21
  • It sets up a local server, but the filesystem is remote. This is why I expected these variables to be set for the remote device, especially when X is being forwarded. – Zhro Jun 19 '22 at 17:43