摘自:https://www.redwireservices.com/remote-x11-for-linux-unix

The Problem

One of my most feared questions from end users is “how can I interact with an X11 GUI application on our remote Linux system if I have no access to the physical console, X11 isn’t installed, and there is no VNC access?”  After hearing this many times at one site, I wrote a script to automate the server side process, but even that does not address the whole story.  I’m writing this post as a quick reference when I field this question in the future, and I hope it helps you, too.

The problem is that most system administrators do not install X11, Xorg, or other GUI interfaces on Linux and Unix systems as this introduces more packages to manage and patch, more security bugs to fix/mitigate, and a larger install footprint (more used space). That last point may seem moot today, but with many environments deploying hundreds of virtual machines, 200-400MB of extra space per VM can really add up quickly (see my latest presentation on Open Source Data Deduplication for more ideas on saving space in these environments).  If you consider the overhead of installing a modern desktop/windowing system such as Gnome or KDE, it could easily more than double the data size footprint of a Linux server.

OK, many environments don’t install the Linux/Unix GUI bits (also known as X11 or Xorg server), so who cares, I can just install everything via the command line, right?  Well, yes, for the most part you can just install applications via the command line and forget this whole issue.  However, there are a few vendor applications, notably including Oracle Database and Application Server products, that are difficult if not impossible to install without a GUI.

The Solution

The modern solution to the problem stated above is to tunnel X11 traffic over ssh (securely), and display it on your workstation, whether it be Windows, Mac OS X, or Linux.  For sake of helping the most folks, we’ll focus on Windows workstations here, but Linux and Mac OS X should work with only the server side changes we write here (just connect with the command line ssh -Y your_username@your_servername.com).

In certain circumstances, it may be advantageous to setup a VNC server to accomplish the same thing, but that requires more of X11 and an windowing environment be configured on the server side, and we’d like to avoid as many server side changes as possible, as many users won’t have access to make these changes themselves.

Process Overview

In order to obtain the ability to interact with an X11 GUI remotely, we will follow these general steps:

  1. Ensure that the foundational X11 packages are installed
  2. Ensure that OpenSSH server is configured to forward X11 connections
  3. Configure a local X11 server on our workstation
  4. Configure our ssh application to forward X11 requests
  5. Test with a simple application
  6. Configured authentication if user changes are needed
  7. Move on with the task at hand

1) Ensure that the foundational X11 packages are installed

In order to use remote X11, you must have a few X11 packages
installed on the server.  In many cases these are already installed, but
you may have to ask your System Administrator to install them for you,
it’s easy:

RHEL/CentOS/Fedora (xterm is optional, but beneficial for testing):

sudo yum install xorg-x11-xauth xterm

2) Ensure that OpenSSH server is configured to forward X11 connections

On RHEL and related RedHat based servers, the file to check is /etc/ssh/sshd_config.  Review this file for the following line:

X11Forwarding yes

If that line is preceded by a comment (#) or is set to no, update the file to match the above, and restart your ssh server daemon (be careful here — if you made an error you may lock yourself out of the server).

sudo /etc/init.d/sshd restart

3) Configure a local X11 server on your workstation

Next we need to install and configure a local X11 server, Xmingor Cygwin/X are popular

Click Xming to start the Xming X11 Server on your Desktop/Workstation

free choices for Windows.  Simply download and follow the install instructions for these packages, Xming is by far easier to setup for beginners.  After the install is complete, and you’ve rebooted your workstation/desktop (if requested), start the X11 server application from the start menu.

4) Configure our ssh application to forward X11 requests

Next, we need to ensure that our ssh client is configured to forward X11 requests from the server.  If you are using Cygwin/X, a Mac, or a Linux desktop, simple open up a terminal and preface your ssh command with -Y, for example:

ssh -Y your_username@your_server.your_domain.com

That will tell SSH to forward all X11 requests to your local desktop.  For Windows, the most popular client is PuTTY.  To achieve the same result in PuTTY, load the profile of the server you wish to connect to, or simply fill out the connection details.  Next expand the Connection and SSH options on the left hand side.  Under SSH and then X11, ensure that Enable X11 Forwarding is checked.

    PuTTY Configuration Window Show X11 Forwarding Enabled.

Finally, click the Open button to connect to the remote server.

5) Test with a simple application

If everything has gone according to plan you now have a server configured to allow X11 connections, an ssh client configured likewise, and you are ready to test.  When connecting to the remote server (last step in part 4 above), you may see a message like this:

/usr/bin/xauth:  creating new authority file /home/ec2-user/.Xauthority

This is a normal message, and in fact it tells us that part of our changes are working!  This file contains an authentication token required to connect with the X11 server.  Now to test, it’s easy, just enter this command on the remote ssh session:

xterm

Wait just a few seconds depending on your internet/network connection speed, and you should see the following.

xterm displayed on Windows from a remote Linux Server

If you see something similar, congratulations!  Remote X11 connections are working!

6) Configured authentication if user changes are needed

X11 forwarding is working, great!  These days, however, users are often not allowed to log in as root, which is great for security, but adds yet another step to our process.  In step 5 we ran xterm as ourselves, which validates our setup is proper.  Try running the same command as another user, though, via sudo and you’ll likely see an error like the following.

X11 Error from Improper Xauth Configuration

The problem here is that a .Xauthority file is created automatically at log in time for our user, allowing our user access to our local X11 server (on our desktop).  However, when root tries to access this connection it is denied without the proper permissions.

To work around this, simply copy the .Xauthority file from your user directory to the user you want to work with (root for example).  Note that this should be done from your user account, not as root:

sudo cp ~/.Xauthority ~root/
sudo /bin/chown root ~root/.Xauthority

Try running xterm again as root, it should work.

sudo xterm

7) Move on with the task at hand

There you have it, now that you can login remotely and still access a GUI as any user, you can move on to installing your GUI centric application such as Oracle.

sudo cp ~/.Xauthority ~oracle/
sudo /bin/chown oracle ~oracle/.Xauthority
sudo su - oracle
./runInstaller

Enjoy!

Gotchas

When installing or configuring an application, like those from Oracle, keep in mind that a break in your internet connection or other problems with your link may cause the remote program to be closed!  So while it may be tempting to let an X11 process run overnight, you may have better results sticking around until the process completes.  If your installer/application stops to ask you a question and your link does fail, you will likely lose all the work completed to that point and have to start all over again.  Save early, save often, as they say.

Conclusion

If this was helpful, please drop us a line at info at redwireservices.com, @RedWireServices on Twitter, or using the contact page.  If you have additional tips to add, please add a comment below and I will update the post accordingly to help as many as possible.

Finally, if you or your company are in need of IT disaster recovery planning, backup system assistance, storage, or archival help, give us a ring at (206) 829-8621.

Remote X11 GUI for Linux/Unix的更多相关文章

  1. LINUX&UNIX 安装vmware workstation10和centOS6

    大一下时,学习了linux&unix这门课程,全字符的操作,我对它并不是很感冒,不过,还是找学长安装过虚拟机和Linux系统,在考前利用它和putty进行复习.现在重装系统之后,各类软件,自然 ...

  2. Linux/Unix mac 命令笔记

    bg和fg Linux/Unix 区别于微软平台最大的优点就是真正的多用户,多任务.因此在任务管理上也有别具特色的管理思想.我们知道,在 Windows 上面,我们要么让一个程序作为服务在后台一直运行 ...

  3. Linux/Unix 线程同步技术之互斥量(1)

    众所周知,互斥量(mutex)是同步线程对共享资源访问的技术,用来防止下面这种情况:线程A试图访问某个共享资源时,线程B正在对其进行修改,从而造成资源状态不一致.与之相关的一个术语临界区(critic ...

  4. 学习linux/unix编程方法的建议(转)

    假设你是计算机科班出身,计算机系的基本课程如数据结构.操作系统.体系结构.编译原理.计算机网络你全修过 我想大概可以分为4个阶段,水平从低到高从安装使用=>linux常用命令=>linux ...

  5. Linux/Unix双机建立信任教程

    Linux/Unix双机建立信任教程 一 需要建立信任关系的2台主机都执行生成密钥输入ssh-keygen -t rsa之后全部默认回车,这样就会在/root/.ssh下生成密钥文件 [root@pl ...

  6. 今天在Mac机器上使用了Flex Builder编辑了一个源代码文件,保存后使用vim命令去打开时发现系统自动在每一行的结尾添加了^M符号,其实^M在Linux/Unix中是非常常见的,也就是我们在Win中见过的/r回车符号。由于编辑软件的编码问题,某些IDE的编辑器在编辑完文件之后会自动加上这个^M符号。看起来对我们的源代码没有任何影响,其实并不然,当我们把源代码文件Check In到svn之类

    今天在Mac机器上使用了Flex Builder编辑了一个源代码文件,保存后使用vim命令去打开时发现系统自动在每一行的结尾添加了^M符号,其实^M在Linux/Unix中是非常常见的,也就是我们在W ...

  7. Linux/Unix 怎样找出并删除某一时间点的文件(转)

    在Linux/Unix系统中,我们的应用每天会产生日志文件,每天也会备份应用程序和数据库,日志文件和备份文件长时间积累会占用大量的存储空间,而有些日志和备份文件是不需要长时间保留的,一般保留7天内的文 ...

  8. Linux Unix 环境变量设置实例

    背景 从第一次写Hello World我们便开始接触环境变量.这最基础的系统设置是必须要掌握的,尤其在是Linux/Unix系统中.比如,哪天某个Java进程出现问题,我们想分析一下其线程堆栈,却发现 ...

  9. Linux / UNIX create soft link with ln command

    How to: Linux / UNIX create soft link with ln command by NIXCRAFT on SEPTEMBER 25, 2007 · 42 COMMENT ...

随机推荐

  1. 效率对比:各种语言构造100W个时间对象

    原本是用perl写了一个通过给定的时间范围来筛选一个比较大的日志文件.但是测试发现筛选130W行日志需要2分多钟,对其中几个低效率函数单独进行了效率测试,发现构造100W个时间对象所花时间也是个大户. ...

  2. 2018.12.1 web项目中解决乱码问题的一个工具类

    <!-- 配置一个过滤器 编码格式的过滤器 --> <filter> <filter-name>encodeFilter</filter-name> & ...

  3. 【luoguP1086】【2004NOIP-Ua】花生采摘

    P1086 花生采摘 题目描述 鲁宾逊先生有一只宠物猴,名叫多多.这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着一张小小的纸条:“欢迎免费品尝我种的花生!――熊字”. 鲁宾逊先生和多多都 ...

  4. 使用TextView/EditText应该注意的地方,监听EditText,addTextChangedListener

    http://blog.csdn.net/huichengongzi/article/details/7818676 监听 EditText 控件: addTextChangedListener(ne ...

  5. GOPL第三章练习题3.3 3.4代码

    练习3.3是peak展示为红色,valley展示为蓝色. 练习3.4是将svg图像打印到浏览器中. // Copyright © 2016 Alan A. A. Donovan & Brian ...

  6. 使用fir.im和蒲公英进行测试的一些注意事项

    前言:使用fir.im和蒲公英进行测试的一些注意事项 最近公司的项目遇到了一个问题,有的用户的手机系统版本低于9.3高于9.0的存在崩溃的情况,8.x的系统的用户的有的界面的显示有问题(比如说图片严重 ...

  7. 关于 NSData 的数据类型(2进制,16进制之间)及深入剖析(转)

    . NSData 与 NSString NSData-> NSString NSString *aString = [[NSString alloc initWithData:adataenco ...

  8. Vue--- VueX组件间通信链接(共有方法放入了扩展目录store里面) 1.2

    Vuex结构图再仔细看 Vuex原理: 就是  把共有属性放入到一个公共的地方,进行使用 多组件共享状态, 之前操作方式,由父组件传递到各个子组件. 当路由等加入后,会变得复杂. 引入viewx 解决 ...

  9. CPU运行的流程

  10. Python 一些好玩的函数

    一.匿名函数 什么匿名是函数: 不需要使用def函数名的函数或者子程序 函数语法: lambda 参数:表达式 函数特点: 1.lambda只是一个表达式,省去定义函数过程,让代码更精简 2.lamb ...