Use real browser instead of w3m on SSH connections
Solution 1
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.
Solution 2
PART 1
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 127.0.0.1 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:
http://linux.die.net/man/1/ssh
http://embraceubuntu.com/2006/12/08/ssh-tunnel-socks-proxy-forwarding-secure-browsing/
https://calomel.org/firefox_ssh_proxy.html
PART 2
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 = 127.0.0.1" (without the quotes, of course).
http://www.debuntu.org/port-forwarding-and-channel-3-open-failed-connect-failed-Connection-refused
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.)
Solution 3
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.
- When connecting with SSH to the server, add the -X flag. For example,
ssh -X myserver
. - 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.
Related videos on Youtube
Pit
Updated on September 17, 2022Comments
-
Pit almost 2 years
I am using Ubuntu as desktop and server OS. When I am logged in to the server via
ssh
onterminal
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
andpassword
, and open on that serverlocalhost
.Is this possible by default, or are there any add-ons for Firefox/Chrome? I would prefer Firefox.
-
Javier Rivera over 13 yearsNot an answer to your question, but... what about using X forwarding?.
-
Carsten Thiel over 13 yearsWhy 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.
-
Pit over 13 yearsIt 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.
-
Javier Rivera over 13 yearsYes, bandwidth is a concern when forwarding X.
-
-
Pit over 13 yearsAs Carsten mentioned in his comment to my question and regarding that the remote server is not in my local network, what about bandwidth?
-
user4124 over 13 yearsYou would need to define your bandwidth requirements. Failing that, you can give this a go and see how it works.
-
Pit over 13 yearsI 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 over 13 yearsOn 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 over 13 yearsI 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). -
djeikyb over 13 yearsWhat? 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 over 13 yearsI 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/…