当我通过 SSH 登录时,为什么我的帐户的 XDG 变量未定义?

当我通过 SSH 登录时,为什么我的帐户的 XDG 变量未定义?

登录桌面后:

$ 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

通过 SSH 登录时:

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

为什么我通过 SSH 登录时的环境不同?

我正在运行 Fedora 30。

答案1

当您登录到桌面时,您的桌面环境会设置大部分 XDG 变量。

当你登录时通过SSH,您看到的唯一变量是由pam_systemd: XDG_SESSION_ID,,,, ;XDG_RUNTIME_DIR​​由于没有桌面环境,因此您不会获得,并且不会为 SSH 连接设置席位信息。XDG_SESSION_TYPEXDG_SESSION_CLASSXDG_SESSION_DESKTOP

答案2

阅读man ssh,你想要-X-Y选项

答案3

阅读后man ssh_configman sshd_config我发现导出的环境变量ssh是由SendEnv以下指令控制的/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.

并且,在服务器上,AcceptEnv(服务器的)中的指令/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.

您的XDG_变量指的是您的桌面会话。简单地将它们按原样复制到另一个系统是没有意义的。

这看起来像是一个“XY”问题。为什么你关心对话XDG_服务器端的变量ssh-X-Y设置一个本地X服务器,并$DISPLAY为你设置。

相关内容