如何从X会话之外运行X程序(例如从控制台或SSH) [英] How to run an X program from outside the X session (e.g. from the console or SSH)

查看:210
本文介绍了如何从X会话之外运行X程序(例如从控制台或SSH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有人在控制台登录,如何运行X应用程序并在X会话上显示它?假设我是根,或者我是登录的同一个用户,所以在原则上我有承诺这样做。

Without being the person logged in at the console, how do I run an X application and have it display on that X session? Assume I am either root, or I am the same user who logged in, so in principle I have persmission to do this. But how do I convince X of this?

这种情况的一些例子:


  • 使用SSH登录并运行在远程计算机屏幕上显示的程序(通过SSH进行隧道传输,这是完全不同的)

  • 通过ImageMagick的 import 命令截取X会话的屏幕截图

  • 运行击键记录器进行审计

  • Log in with SSH and run a program that displays on the remote computer's screen (not tunneled through SSH—that is totally different)
  • A cron job to take a screenshot of the X session via ImageMagick's import command
  • Running a keystroke logger for audit purposes

这是一个更简单的版本直接从无窗口的Linux终端启动OpenGL应用程序

This is a simpler version of Launch OpenGL app straight from a windowless Linux Terminal

推荐答案

您必须设置 DISPLAY 环境变量,然后应用程序将运行。

The short answer is that you have to set the DISPLAY environment variable, and then the app will run.

我们有Xauth,除非你在同一台机器上运行同一个用户,这可能不会工作,除非您从运行X服务器的帐户导出Xauth凭据到运行X客户端的帐户。 ssh -X 为你处理这个,这是为什么它真棒,但手动过程涉及运行 xauth extract - $ DISPLAY 在X服务器帐户上并将该数据提供给客户帐户上的 xauth merge - 。 (警告:数据是二进制的)

The long answer is that we've got Xauth, and unless you're running as the same user on the same machine that's probably not going to work unless you export the Xauth credential from the account running the X server to the account running the X client. ssh -X handles this for you, which is why it's awesome, but the manual procedure involves running xauth extract - $DISPLAY on the X server account and feeding that data into xauth merge - on the client account. (Warning: the data is binary.)

在现代Linux系统上,有一个X会话在0,X11权限数据文件总是 $ HOME / .Xauthority ,因此您通常可以设置两个环境变量,例如在Bash中:

On modern Linux systems, there is one X session at :0 and the X11 authority data file is always $HOME/.Xauthority so you can most often set two environment variables, for example, in Bash:

export XAUTHORITY=/home/$your_username/.Xauthority
export DISPLAY=':0'

这篇关于如何从X会话之外运行X程序(例如从控制台或SSH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆