Xhost
lastmod 2025-02-14created 2020-09-059 edits
By default, X only permits displaying X applications running on the same terminal as the X server. To permit connections from other terminals, use xhost.
Controls who accesses Enhanced X-Windows on the current host machine.
Usage
Description
The xhost command adds or deletes host names on the list of machines from which the X Server accepts connections.
This command must be run from the machine with the display connection. You can remove a name from the access list by using the -Host parameter. Do not remove the current name from the access list. If you do, log off the system before making any corrections.
Entering the xhost command with no variables shows the current host names with access to your X Server and a message indicating whether or not access is enabled.
For security purposes, the options that affect access control may only be run from the controlling host. For workstations, this is the same machine as the server. For X terminals, it is the login host.
To enable a remote name by default, the name can be defined in the /etc/X?.hosts file, where ? is the display number to which access is enabled.
For example, the display jeanne:0 can be accessed by systems defined in the /etc/X0.hosts file on a system that uses jeanne as its default host name. In both the display name and the file name, the 0 indicates the display number that the defined remote systems are allowed access to by Enhanced X-Windows.
Flags
-
+Name - Defines the host name (the plus sign is optional) to be added to the X Server access list.
-
-Name - Defines the host name to be removed from the X Server access list.
- Existing connections are not broken, but new connection attempts will be denied. You can remove the current machine; however, further connections (including attempts to add it back) are not permitted.
- The only way to allow local connections again is to reset the server. (This breaks all connections.)
-
+ - Specifies that access is unrestricted. Access control is turned off.
-
- - Turns access control on.
Name uses the family:name format:
-
inet- Internet host -
local- Contains only one name, the empty string
| NOTE |
| "family" is case-sensitive. The format of "name" depends on "family". |
Communication socket location
On Unix-like systems: /tmp/.X11-unix
Examples
Allow local users to connect
If you don't know much and just want to make the X server accessible:
Specify servers allowed to connect
The following example displays X applications from 192.168.11.12 on the X server you are using.
You can check that it runs correctly with xeyes.
Display syntax
The format for specifying an X server is as follows.
-
X서버명(X server name): an IP address or a host name that can be resolved via name resolution. -
디스플레이번호(display number): the number of the X session; it is required for-display. -
스크린번호(screen number): identifies the display used by the X server. If omitted, the default is0.
If you are only adding the host running the X client to be permitted with xhost, you can omit the + and specify just the IP address. However, be careful: if you write only + without a target IP address, every host that can connect over TCP/IP will be able to access the X server.
You can also specify by user name. The following example permits connections from the user rino on localhost.
Check the current access control status
Just run xhost without options.
The output looks like this:
Running in Docker
- How to integrate a GUI with Docker
- Running Pygame in a Docker container (MacOS)
- Running GUI and GL programs inside docker – ahnbk.dev
First, on the host machine, set permissions so that every program run by the user named docker can access the X window:
Check the DISPLAY environment variable:
Run Docker:
Then, in the guest (inside the container):
apt update
apt install x11-apps
xeyes
## 또는 OpenGL 테스트를 하고싶다면:
apt update
apt install mesa-utils
glxgears
To restore the X window access permissions:
Instead of the docker user, you can also set it to the user logged in to X windows, as below.