43

I currently have an html file on a remote unix server that I ssh to. I have been using SFTP to constantly transfer it to my local machine to view it after my edits, but I am tired of this.

What is the best program/method for Mac users to have a browser window view of the html file that is stored in a remote unix server? Or is there an ssh client that can easily edit html files?

1
  • 1
    If you simply need to view the file over a console session, I suggest links/lynx, which are text-based web browsers. Otherwise, as Benny Hill said, just use a standard *nix editor. Commented Jan 14, 2014 at 22:26

2 Answers 2

74

It is possible, but with some playing around on the server.

Once you have ssh'ed into the server, install a web server in that box. Say the file is named index.html, you should make it available at the URL http://localhost:8000/index.htmlor port number can be anything.

The simplest method I can think of starting a web server at that location is

cd /directory/where/html/is/present
python -m SimpleHTTPServer 8000  # For python 2
python3 -m http.server 8000 # For python 3

This works provided python is installed on the server. It should not be that hard to install it as python is available from almost every package manager in every flavor of linux.

Now that html is available at python

http://localhost:8000/index.html

on that machine.

But we have not yet configured the browser in such way.

To do that you need to ssh into the server again, but with a -D option this time

ssh servername -D 7000

-D specifies application level tunneling when connecting via ssh

Then in Firefox, preferences/options -> Advanced -> Networks -> Connection Settings -> Choose Manual Proxy configuration

SOCKS HOST should be localhost , port no 7000.

Then the html should be directly available at

http://localhost:8000/index.html

in your Firefox browser.

This feature is only available in the Firefox browser.

Sign up to request clarification or add additional context in comments.

4 Comments

Impressive. The only thing I had to change was the URL, the html was stored at 0.0.0.0:8000/index.html Thank you so much!!!
With python3, you need to use python -m http.server 8000 instead
You can skip the proxy by doing a port forward e.g. ssh -L 8000:localhost:8000 you@server, this binds your local machine port 8000 to the remote port 8000.
To add to @C.Hammill 's excellent tip, the first port number is the port you want to use on your local machine, the second one is the port used by the service on the remote machine. So, if you have to use different numbers to avoid conflicts with other local services, you can. ssh -L 9999:localhost:8000 then open your browser to localhost:9999 instead
8

You can mount the remote directory with sshfs which gives you easy access to all the files. E.g.:

sshfs user@server:/directoryToMount /localDirectory

2 Comments

Looked really promising but for brew installing on Mac: Error: sshfs has been disabled because it requires closed-source macFUSE! :(
I have no problems with mounting on a Mac (both Intel and M1) . To install MacFuse follow the two links in the first paragraph of github.com/osxfuse/osxfuse/wiki/SSHFS . Be careful to install both, ssh and osxFuse. To enable sshfs on your Mac go to: System Preferences -> General tab -> Allow Extensions button Then follow the instructions that pop up (make sure that you remember the instructions before shutting your computer down).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.