SSH X forwarding in program using "system" command
I've run into a nuance of ssh that I'd like to solve. Here's the setup:
I'm running a GUI program that launches commands via the "system" function. One such command is 'ssh -X account@remote "./startup"'. Inside the 'startup' script, I set the display variable to localhost:10.0. The desired result is that the X window of the remote program shows up locally. It works when in a terminal: 1. ssh -X account@remote <enter> ./startup Setting DISPLAY explictly is redundant here because the .bashrc is run. 2. ssh -X account@remote "./startup" Setting DISPLAY explicitly in script needed because it doesn't get set. In the program, the call 'system("ssh -X account@remote \"./startup\"")' yields a 'Can't open display: localhost:10.0'. Here's the kicker though, it works if ANOTHER terminal is already sshed into that machine. This probably has something to do with the .Xauthority file. My question is how can I make this work WITHOUT having to ssh into the machine from another terminal? Any other approaches to this are welcome. Test script on remote machine (replace gcalctool with any X windows program) Code:
#! /bin/bash Code:
#include <stdlib.h> |
I found the error...
I use an alias for ssh=ssh -X. When running the 'system' call, it doesn't use the alias. I had to explicitly use the -X for the X forwarding to work. There is no way anyone could have guessed that from the information I provided. Lesson learned - 'system' does NOT run your .bashrc script! |
Instead of putting the -X into an alias, I suggest to define it in your ~/.ssh/config file which will always be used:
Code:
Host foobar |
All times are GMT -5. The time now is 04:52 PM. |