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

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

问题描述

如果不是在控制台登录的人,我如何运行 X 应用程序并将其显示在该 X 会话中?假设我是 root 用户,或者我是登录的同一用户,所以原则上我有权这样做.但我如何说服 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 会话屏幕截图的 cron 作业
  • 出于审计目的运行击键记录器
  • 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 终端

推荐答案

简而言之,您必须设置 DISPLAY 环境变量,然后应用才能运行.

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

长的答案是我们有 Xauth,除非您在同一台机器上以同一用户身份运行,否则可能无法工作,除非您将 Xauth 凭据从运行 X 服务器的帐户导出到该帐户运行 X 客户端.ssh -X 会为您处理这个问题,这就是它很棒的原因,但是手动过程涉及在 X 服务器帐户上运行 xauth extract - $DISPLAY 并将该数据提供给 <代码>xauth 合并 - 在客户帐户上.(警告:数据是二进制的.)

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 系统上,在 :0 处有一个 X 会话,X11 权限数据文件始终为 $HOME/.Xauthority,因此您通常可以设置两个环境变量,例如,重击:

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 会话外部(例如,从控制台或 SSH)运行 X 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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