Opening Browser in remote machine through ssh

I need to open browser with specific url using ssh through a remote machine, i have enabled password less connection, i am able to get command o/p which run on remote machine using ssh, but how can i open browser using ssh? Tried with "-X" option which will open remote machine browser in my machine ( considering i run ssh from my machine).

Tried
1). ssh client@IP_ADDRESS -X "firefox - this opens browser in my machine.
2). ssh client@IP_ADDRESS "firefox this command shows error saying Error: no display specified.

Basically, my requirement is , through my machine, i should launch browser with specific url in remote machine ( which is suse linux).

Any pointers are greatly helpful.

Thanks.

3 Answers

You need to set the DISPLAY environment variable. See env |grep DISPLAY. So basically you could use something like export DISPLAY=:0; firefox .

2

Thank you all for the reply. I got this working with the help of 2 scripts
On Server side ( or in my machine) i have a script which looks like this

#!/bin/bash
ssh client@IP_ADDRESS "nohup sh openBrowser.sh $1" &
PID=$$;
echo "PID IS |$PID|\n";
sleep 3 && kill -9 $PID;

On the client side ( where i need to open browser remotely i have a script ( openBrowser.sh) which looks like this

#!/usr/bin/sh
#read " as backquote
browserPID="ps aux | grep firefox | grep -vc grep";
if [[ "$browserPID" > 0 ]];
then
    killall -9 firefox
fi
nohup firefox --display=:0 $1 &

Also point to ensure that, i have created password less connection using ssh-keygen.
On the server i call the script (first one) as
sh launchBrowser_client1.sh
this would open google.com on client.

Your pointers on solving this appreciated.

Thanks.

You need a display to run it on. You specify that display using the DISPLAY environment variable.

If you don't want to shove all the data over SSH then you need to use an X11 server on the machine you are connecting to. This could be a headless server such as xvfb.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like