LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 11-30-2012, 12:31 PM   #1
JayKemper
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Rep: Reputation: Disabled
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

export DISPLAY=localhost:10.0

gcalctool
Program to execute command:
Code:
#include <stdlib.h>
int main(int argc,char *argv[])
{
    system("ssh -X account@remote \"./startup\"");
    return 0;
}
BTW, using mostly CentOS 5, and one machine is Fedora Core 2 (I know, but it's got special hardware)

Last edited by JayKemper; 11-30-2012 at 12:33 PM. Reason: Added distribution info
 
Old 11-30-2012, 02:04 PM   #2
JayKemper
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
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!
 
Old 12-01-2012, 03:46 PM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
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
    hostname remote
    user account

Host *
    ForwardAgent yes
    ForwardX11 yes
    ForwardX11Trusted yes
    Compression yes
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh / sshd config: how enable "tunneling with port forwarding on the network"? frenchn00b Linux - Server 1 08-30-2009 02:57 PM
Supplying "password" to "ssh" command paragkalra Linux - Networking 1 07-31-2008 06:19 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
list file system linux supports "please give the command or system call" varun_shrivastava Linux - General 4 01-09-2007 08:28 AM
C -communicating with system("ftp"); using "program|ftp>>myfifo" probably hansschmucker Programming 1 03-23-2005 02:39 PM


All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration