9

When I ssh into my server and do my things there. How can I for example open a browser on the remote machine, and display it on my local machine,

I run Ubuntu desktop on my local machine. On server side I use Ubuntu 16.04 server. Its a development server so I have a python script there that use:

webbrowser.open("https://" + url)

to open default browser with the URL I need.

In other words how can I when I'm logged into the server, open a link on my local machine.

In more general words, how can I use my Ubuntu remote server machine as if its my local machine?

Since:

  • A serverside machine doesn't NEED a GUI.
  • I don't want to install a server GUI and use REMOTE DESKTOP.

How can I access my own development server and open a simple program on my local machine?

3
  • 1
    webbrowser.open runs the $BROWSER variable with URL as argument, by default. You would need a program, when executed, would forward this to your local computer.
    – vidarlo
    Feb 12, 2018 at 16:56
  • If you want the browser to run on the remote machine but display on the local machine, you need to have the browser installed on the remote machine and X11 forwading enabled when you connect via SSH.
    – muru
    Feb 13, 2018 at 12:31
  • The only thing I can think of here is that you need to set up a share on your server that you can map via Samba or something that will allow you to mount your scripts folder to the local host so that you can run the scripts from there on the local system.
    – Terrance
    Feb 19, 2018 at 2:33

2 Answers 2

13

The easy way to do this, is to use SSH's socks proxy. From the man page:

-D [bind_address:]port

Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine.

Browsers can also use socks proxy. How to configure it depends on which browser you happen to use, but I typically use one browser for work over socks, and another for non-proxied work.

First, start ssh with the following command:

ssh -D1080 [email protected]

This will run ssh, creating a socks proxy to the remote host, listening on port 1080. In your browser, enter a socks proxy on localhost, port 1080. In Firefox this is located under Preferences - Advanced - Network:

Firefox proxy settings

This will tunnel traffic from the browser to the remote machine, and traffic will appear to be sourced from the remote machine.

6
  • What do i need to change in browser settings ?
    – An0n
    Feb 11, 2018 at 9:57
  • You need to change the proxy settings. I've even included a picture indicating how to do it for firefox
    – vidarlo
    Feb 11, 2018 at 9:57
  • It still doesnt open firefox when i type firefox in ssh terminal. It also says firefox not installed.
    – An0n
    Feb 11, 2018 at 10:41
  • 2
    No, you do the change in your local browser, and ssh tunnels the traffic to the remote host for you. You don't need (and probably shouldn't) have firefox installed on the remote end.
    – vidarlo
    Feb 11, 2018 at 10:41
  • 1
    Such information should be included in the question... But this answer tells you how to achieve that. Note that unless you have good latency and bandwidth it will be slow.
    – vidarlo
    Feb 11, 2018 at 10:46
7

First, in your server sshd_config, enable X11 forwarding as follow

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

Then ssh in your server:

$ ssh user@server -C -X

Then launch firefox

$ firefox
11
  • Then it says firefox is not installed.
    – An0n
    Feb 11, 2018 at 10:31
  • 1
    Then install Firefox. sudo apt-get install firefox should take care of that.
    – vidarlo
    Feb 11, 2018 at 10:48
  • I dont need firefox on my server since it must open on local machine..
    – An0n
    Feb 11, 2018 at 10:51
  • If you want to run firefox on the remote end you do need it. Otherwise you will have to replace your commands in the script with something that sends the command to your local machine, which - again - is not what you are asking.
    – vidarlo
    Feb 11, 2018 at 10:53
  • 3
    OP says "I do not have a GUI on the server" - wouldn't they need to install not just Firefox but some version of X (i.e. a GUI) on the server in order to do this? If they want to "open a browser with Firefox *on the remote machine*" (emphasis added) then this is the correct answer. If they want to run firefox locally, the other answer is right
    – Adam
    Feb 11, 2018 at 11:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .