Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

SSH and X11 forwarding

I would like to login into a remote host using SSH and use a specific X11 server on my local host.

I am doing this because a particular application will only work in 8-bit color, so I setup a second local X11 session running a 8-bit server. I can use this fine if I set the DISPLAY option explicitily everytime I login in to point to my localhost, and second X11 port number. I would set this permenantly, but my local host name changes because I am a DHCP host.

How can I pass the localhost name to the remote host when I start a SSH session from my Mac? I can't use the SendEnv/AcceptEnv because I don't have admin privilages on the remote host to configure SSH. The REMOTEHOST environment variable does not get set when I login.

Thanks



iMac G5 Mac OS X (10.4.6)

Posted on Jun 12, 2006 11:47 AM

Reply
7 replies

Jun 12, 2006 12:38 PM in response to David Fass

Yes, I could, and currently do, set my REMOTEHOST manually when I log in.

But the point of this e-mail is that I want to automate this.

How would I script it? I don't have a way of looking up the client address on the host I am ssh'ing into.

For instance. I am on HOST-A. I ssh into HOST-B. Now, once I have logged into HOST-B, how do I get the address of HOST-A? The environment variable REMOTEHOST does not get set. Is there another variable, or way to access this?

The -Y (or -X) uses the default X11 server (REMOTEHOST:0.0). I need to set that to a specific server: REMOTEHOST:1.0.

Thanks



Mac OS X (10.4.6)

Jun 12, 2006 1:26 PM in response to Albion

i'm a bit confused - you should not have to do any setenv'ing to get X11 forwarding to work. looking around on my machine and on network machines from which i forward X11, the only setenv DISPLAY command i have in any .tcshrc anywhere is on host-a, and it's:
setenv DISPLAY 😮.0

after you ssh into host-b, and you have X11 running on the machine you're physically typing on (host-a i assume), what happens if you enter the command 'xterm &' ? if nothing, X11 forwarding isn't working.

in that case, the first thing i'd suggest is to take a look at /etc/ssh_config on host-a. there should be two lines that look like this:
ForwardAgent yes
ForwardX11 yes

in /etc/sshd_config, you should see:
X11Forwarding yes

if these lines are commented ("#") and/or include "No" not "Yes", edit these two files to make these changes, then log out and in again, then try to forward an xterm again...... cheers

Jun 12, 2006 2:01 PM in response to W.J. Llope

OK, the important thing to see here is I am running a second 8-bit X11 server at display 1.0 to make an application run that only works with 256 colors.

Sure, starting xterm& at a prompt brings up a new terminal, on display :11.0. I need to explicitly be able to set the display to use display 1:0 in order to use my second X11 server running in 8-bit color. My program would need something like this

my_program -display my host_name_oraddress:1.0

Normally DISPLAY is set to localhost:11.0 if I login using ssh -X (or -Y) and everything displays to the default display. I need to know how to aquire the client address "my host_name_oraddress" in order to use the above command. Of course I can manually set this everytime I log in, and that is what I am doing.

My question is how do I aquire the client address so I can set the alternate display option properly. Everything else works great provided I input my computers address along with the alternate X11 display after I login.

Does that make sense? Let me be a little more specific while I am at it.

In my .xinitrc file I run the following script

# Start a new Xquart display in 8-bit mode
#
Xquartz :1 -depth 8 -displayID 1 >& /tmp/quartz.log >& /dev/null &
#
# Set the display ID of the new X display to 1
#
DISPLAY=localhost:1.0
export DISPLAY
#
# Start a new window manager on the new display to handle windows and events
#
quartz-wm&

Notice it uses a second X11 server to display at 1:0.

I need to be able to set DISPLAY to point at that server and window manager to make my 8-bit program work properly.

Thanks

Albion

Jun 12, 2006 2:17 PM in response to Albion

Hey Albion:

I do something similar using xnest. Here is an example. I am afraid it is in zsh, not tcsh, but there is probably some hideous way to translate it (or you could make the switch, and dump the bi...).

This runs xdlmapman in a separate window.

First I have this function in my .zshrc:


<pre>
function xdlmapman {
xinit ~/.xenmapman -- /usr/X11R6/bin/Xnest :99 -geometry \
1200x900 2>| /dev/null &
}
</pre>

Then I have this file: ~/.xenmapman

<pre>
#!/bin/zsh
# Execute evilwm or twm session with xdlmapman and an xterm to list

# This should be inherited, but take no chances
source /sw/bin/init.sh &

# start the xdlmapman program
$CBIN/xdlmapman &


command xterm -geometry 80X25 600400 -bg black -fg white -sb \
-sl 1000 -rightbar -T "$PWD" -e '/bin/zsh -c print " "; \
print "\e[1mPlease select a map file by highlighting it:\e[0m" ; \
print " "; ls *.map; print " "; \
print "\e[1mThen paste it in the \"Read a New Map File\" dialogue \
box\e[0m "; print " "; /bin/zsh' &

if [[ -x /sw/bin/evilwm ]];then
exec /sw/bin/evilwm -bg blue -fg RoyalBlue3 -bw 5
else
exec /usr/X11R6/bin/twm
fi

</pre>

So what I get is entire environment nested in one window. I am using evilwm since it is lightweight, but you can use whatever suits you.

Jun 12, 2006 5:18 PM in response to Albion

Hi Albion,
I don't know how to find the hostname of the client but you can set the DISPLAY using an IP address and SSH provides that for you. When you use OpenSSH to connect to a remote server it sets some environment variables in the shell on the remote server. Among these is the SSH_CLIENT environment variable, which contains three fields, separated by spaces. The first is IP address of SSH client machine. I would think that you could use that to set the DISPLAY to make X11 forwarding work.
--
Gary
~~~~
One-tenth of the participants produce over
one-third of the output. Increasing the number
of participants merely reduces the average output.
-- Norman Augustine

Jun 13, 2006 1:11 PM in response to Gary Kerbaugh

Well, I had thought of using that variable, but was wondering if there was an alternate, cleaner way to do it. In the end this is my Perl hack

######################################
#!/usr/bin/perl -w
#
# Aquire the remote host address for displaying
# to a remote X11 server
#
# Get the SSH client environment variable value
#
my $env = $ENV{'SSH_CLIENT'};

#
# Remove carrige returns, and parse the value,
# first colon seperated, then by whitespace
#
chomp($env);
my @env_list = split(/:/,$env);
my @add_list = split(/ /, $env_list[3]);

#
# Now print the resulting value
#
print $add_list[0],"\n";
######################################

I call this from my .cshrc file to set the REMOTEHOST environment variable so other applications have access to it

setenv REMOTEHOST `getremotehost.pl`

Thanks to all who replied.

Albion

iMac G5 Mac OS X (10.4.6)

SSH and X11 forwarding

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.