Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Global xhost setting for X windows UNIX
After I set up X windows I ran into a small problem: I run X windows applications on a number of servers at work (some of them are randomly chosen by the application), but I don't want to have to use "xhost +" to allow any machine to access my X server (doing so opens up all kinds of security risks). Issuing multiple xhost commands in my .cshrc file works well enough, but when .cshrc is run by, I get an ugly error for each xhost command.

The solution I found is to create a file "/etc/X0.hosts" (that's x-zero) which includes the names of all hosts that shall be allowed to open windows on my system. It's global, and thus not an ideal solution, but it works for me.

If you have a better solution please let me know!
  • Currently 3.00 / 5
  You rated: 3 / 5 (1 vote cast)

Global xhost setting for X windows | 6 comments | Create New Account
Click here to return to the 'Global xhost setting for X windows' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
What's the ugly error?
Authored by: jimhill on Dec 11, '01 02:14:18AM

Depending on the nature of the "ugly error", you may be able to eliminate it while keeping the xhost statements in your .cshrc if you wrap them in a conditional. I don't do csh and haven't in ages so I can't give a syntactically correct example.

[ Reply to This | # ]
What's the ugly error?
Authored by: adrianu on Dec 11, '01 11:11:00AM

In your .cshrc, wrap the xhost commands as follows...
if( $?DISPLAY ) then
  xhost commands go here...
This will make sure that the DISPLAY variable is set before trying to execute the xhost commands... I do recommend the ssh way, though - if you are connecting to a machine that does not have ssh running then ask the owner/administrator WHY NOT!! Bye! Adrian

[ Reply to This | # ]
X11 Forwarding
Authored by: lx on Dec 11, '01 10:29:48AM
If your remote systems have ssh installed (highly recommended), then you can use X11 forwarding with -X option (e.g. "ssh -X" will give you a secure shell on the remote computer with X11 forwarded). Advantages here include secure X11 sessions and the possibility of using key based authentication which allows you to avoid typing in your passwords all the time or storing them in an insecure shell script. For more information, see the OpenSSH FAQ, as well as Daniel Robbins' deloperWorks article on ssh key management (see also Part II).

Reply to This | # ]
A snap using OroborOSX
Authored by: baba on Dec 11, '01 11:48:56AM

This is quite easy if you're using the window manager, OroborOSX. Provided with the manager is
a template for your own Launch Menu items. A snippet for a modified app, named 'addhosts.x11app' is below.
Add one line to the end of the StartupItems file in the Launch Menu Items folder:
and the app will be called at startup. It will also be available in the menu.

set appname="xhost"

set usepath="/usr/X11R6/bin"

set argums=""

# OPTIONAL TITLE STRING GOES HERE (comment this if not needed)
# note that an ID number, sent from OroborOSX, will be added in
# brackets after this string [eg, below would give "xterm (3)"]
set titlenam="xterm"

[ Reply to This | # ]
X Commands in Terminal
Authored by: jdbyler on Dec 13, '01 05:44:54PM
The xhost command (and just about any other X command) will not work without the DISPLAY variable being set. In order to set DISPLAY automatically in Terminal windows, I use this code in my .cshrc:
  if ($?TERM_PROGRAM) then
    # Only run these commands if the shell is launched by Terminal
    setenv DISPLAY :0.0
You could combine this with adrianu's suggestion for running xhost commands only if DISPLAY is set. I recommend using ssh -X, though, for security.

[ Reply to This | # ]
using x11 to run remote apps on AIX?
Authored by: gdghorn on Feb 28, '03 10:13:47AM

I've tried setting display and running xhost +, but still get the "Error: Can't open display:" error running xclock. Someone hinted that I needed a .xhost? file or a .rhosts entry on the AIX side....anyone have experience with this? Thanks.

[ Reply to This | # ]