I am using Ubuntu as desktop and server OS. When I am logged in to the server via ssh on terminal and have to view a web-page (localhost) on the server I use w3m (w3m localhost).

Unfortunately w3m is not that easy to handle, as the page has some big menus and uses jQuery. So I am wondering if it is possible to use a browser on my Desktop to connect to the server via SSH with a real browser (Firefox or Chrome).

Basically it would require to connect with a browser on my desktop to the server over SSH with username and password, and open on that server localhost.

Is this possible by default, or are there any add-ons for Firefox/Chrome? I would prefer Firefox.

  • Not an answer to your question, but... what about using X forwarding?. – Javier Rivera Jan 26 '11 at 8:16
  • 1
    Why can you not connect to the remote server via http? Do you specifically need the request to originate from localhost for testing purposes? @Javier X forwarding, especially for firefox, is heavy on bandwidth and I would not recommended it for non-local connections. – Carsten Thiel Jan 26 '11 at 8:29
  • It is on the one hand for testing purposes so it needs to be localhost. On the other hand the remote server is not in local network and can not be reached over normal http. – Pit Jan 26 '11 at 9:13
  • Yes, bandwidth is a concern when forwarding X. – Javier Rivera Jan 26 '11 at 9:49

Use ssh port forwarding.

Connect to the remote server with something like this:

ssh -L 8080:localhost:80 user@remoteserver

Now, point your local browser to localhost:8080. It should be forwarded to localhost:80 in the remote server.

  • I just tested this on a server in my local network, and it seems to work. I will test it later with the remote server. – Pit Jan 26 '11 at 14:07


Make a socks proxy with ssh!

ssh -D 9999 user@remoteserver

Now open your Firefox preferences, go to Advanced > Network > Settings. Select Manual proxy configuration. Put localhost for the SOCKS Host, put 9999 for the port. Test it by going to http://whatismyip.org or some similar site.

Because you said you're trying to access a web page at localhost (relative to your server), you may not want to exclude localhost and from using the proxy. Of course, you could just use the local ip of the server..

If you don't like my explanation, these links jogged my memory while writing this:





The error you got, channel 3: open failed: connect failed: Connection refused has absolutely nothing to do with ssh. Apparently you're trying to access some mysql thing. This has an extra challenge, because mysql blocks access from ssh tunnels by default. I don't do mysql, so I don't know what I'm talking about for the rest of this. I'm just quoting the relevant bits of the link at the end, which you should read.

Open /etc/mysql/my.cnf and look for the [mysqld] section. If you see a line "skip-networking", comment it. Add "bind-address =" (without the quotes, of course).


Part 3

Javier's solution ssh -L 8080:localhost:80 user@remoteserver is fantastic if you just need access to the one location. It lets you access localhost, and leaves the rest of your internet alone. My solution with ssh -D goes farther, and will actually direct all of your http requests to the remote server. Obviously you might not actually want this. But I've found it useful when I wanted http access to all machines on a network, or when I didn't want my http requests going through the network I'm wired into (ie, online banking at starbucks. All my traffic goes through the ssh tunnel to my home internet.)

  • On requesting 'localhost' in firefox I get an error in the terminal where I opened the ssh connection: channel 3: open failed: connect failed: Connection refused. I did not have time to look it up, but perhaps you know what it could be? – Pit Jan 26 '11 at 14:12
  • I just saw in the man page of ssh that you need to be root to use the -D option. This is the reason it did not and will not work, as I can't connect as root to the server (for security reasons). – Pit Jan 26 '11 at 16:53
  • What? I used this all the time as a normal user on both ends of the tunnel. Oh I see. You must be root if you try and use a port like 80, or 21, or any of the other IANA reserved ports. Anything over 1024 ought to be fine. I think the error has to do with your ssh.conf blocking forwards. I'm googling along those lines now. – djeikyb Jan 26 '11 at 22:00
  • I googled your error, and came up with this article that says mysql has a security "feature" that blocks access from port forwards by default. debuntu.org/… – djeikyb Jan 26 '11 at 22:08

You can use X forwarding through SSH so that any X applications that you run on the server would show up on your personal computer.

  1. When connecting with SSH to the server, add the -X flag. For example, ssh -X myserver.
  2. Install a GUI browser on the server and simply run it. The output will appear on your personal computer through X forwarding and the secure SSH connection.
  • As Carsten mentioned in his comment to my question and regarding that the remote server is not in my local network, what about bandwidth? – Pit Jan 26 '11 at 9:16
  • You would need to define your bandwidth requirements. Failing that, you can give this a go and see how it works. – user4124 Jan 26 '11 at 10:04

Here's a comrehensive solution:

  1. Make a tunnel (dynamic port forwarding) over SOCKS5 protocol using ssh:
    ssh -ND 9994 -C user@YourSshServer
    or if you have to use a specific port to SSH:
    ssh -ND 9994 -C -p xxxx user@YourSshServer

  2. Configure the FireFox preferences via searching Network Proxy and hit on Settings... as follows:
    enter image description here

Now the FireFox is able to browse over all of the existing HTTP ports properly.

You can also use another approach like @Javier Answer in which you can reach to a specific port from the remote server by the following command without any configuration on your browser:

ssh -NL <dummy-port>:localhost:<intended-port> -C user@YourSshServer


ssh -NL 8080:localhost:80 -C user@YourSshServer

Now the 80 port from the remote server is linked to the 8080 port and you can easily see it on any browser through localhost:8080.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.