永久配置 xhost 的步骤
尝试将 X-Windows 应用程序显示/重定向到最近重新启动的服务器的用户/主机,该服务器未专门配置为允许访问其 X-服务器,将收到以下(部分)错误,直到系统管理员运行 xhost 命令:
... Xlib: connection to "host01.example.com:0.0" refused by server Xlib: No protocol specified ...
要将 xhost 配置为在 Linux 服务器重启后保持不变,请执行以下步骤。
确定我们希望授予/拒绝访问 X 服务器的可信/不可信主机列表(主机名或者 IP 地址)。
作为特权用户 (root),将以下行添加到文件 /etc/profile 文件中,用我们在步骤 1 中确定的主机名替换主机名。
... if [ "$DISPLAY" != "" ] then xhost +host01.example.com +host02.example.com +host03.example.com +host04.example.com xhost -host05.example.com fi #eof
在上面的示例中,系统配置为授予主机 host01 、 host02 、 host03 和 host04 连接(即显示/重定向其 X 显示)到它的 X 服务器的能力,但限制主机 host05 。
请注意,主机名必须是可解析的,例如:它们必须存在于 /etc/hosts 或者 DNS 中。
以上还假设使用 bash (/bin/bash)、bourne (/bin/sh)、korn (/bin/ksh) shell。
此外,当添加到 /etc/profile 文件时,xhost+ 命令仅在用户以图形方式登录并保持登录系统时执行和设置。
为了安全起见,当用户注销时,xhost 设置会被重置。
要使 xhost 设置保持持久,用户必须以图形方式保持登录系统。
- 有了上述内容,以 root 身份执行/获取 /etc/profile 文件(我们可能需要 chmod 文件才能执行(即 #chmod u+x /etc/profile)和/或者重新登录到系统以 root 身份以图形方式运行,其中应该观察到类似于以下内容的内容。
[root@host01 ~]# /etc/profile host01.example.com being added to access control list host02.example.com being added to access control list host03.example.com being added to access control list host04.example.com being added to access control list host05.example.com being removed from access control list
每次登录服务器时都会显示授权/未授权主机列表。
xhost 命令是 Linux X-Windows 服务器访问控制程序。
根据使用的参数,xhost 授予或者拒绝用户/主机对本地 X 服务器的访问(连接),从而允许或者拒绝用户/主机显示基于 X-Windows 的应用程序的能力,例如xclock、图形安装程序等。
这篇文章的目的是描述如何将 xhost 配置为在 Linux 服务器重启后保持持久,从而确保用户/主机可以在没有特权用户干预的情况下继续显示 X-Windows 应用程序。