How can I view pictures via ssh

138,095

Solution 1

You haven't said what Operating System you are connecting from. If you are using a *nix running an X server, you can use ssh X forwarding. This will enable you to run graphical applications on the remote server and have them displayed on the local machine. For example:

ssh -Y user@server
eog pictures/foo.png

Assuming the server has eog installed, this should cause the image to be opened and displayed on your screen.

For future reference, when asking questions on this site it is a good idea to specify the system you are using because the correct answer will often depend on it.

Solution 2

if you are on OS X, using iTerm2, you can do imgcat and display the image right in the terminal.

https://www.iterm2.com/documentation-images.htmlenter image description here

Solution 3

I've tried a few of the methods listed by other answers on this page, and I've tried them on both Ubuntu 20 and MacOS Mojave (my machine is a dual-booted abomination). On both systems I found that using the -X flag with ssh and then eog works, but is a bit slow and clunky. X-forwarding can be fine if you're browsing through small directories, but can become completely unusable if the directory you're working in has large amounts of data.

The best method I've seen is sshfs. It's a piece of cake to set up and I've found it to be extremely flexible. Basically it mounts the remote file system as a local drive, allowing you to either view the remote files or transfer files between your local runtime and the remote host - much easier and more intuitive than scp (though scp is a useful skill to know).

Ubuntu

I'm not sure about previous versions, but Ubuntu 20.04 came with sshfs. If your version of Ubuntu doesn't have it, you can install it with

sudo apt install sshfs

To use it, you will need an empty directory. I have mine in my home directory and have named it sc. To set it up you run the command:

sshfs -o follow_symlinks <user>@<server address>:/ ~/sc

Voila! When you use your file explorer or terminal to open sc you'll see the remote drive mounted.

MacOS

The steps are nearly the same as the ones for Linux/Ubuntu. The difference here is that MacOS doesn't come with sshfs installed, and sshfs also requires some dependencies that also aren't included in MacOS. So first, we install these dependencies with:

brew install osxfuse

Now we can install sshfs with:

brew install sshfs

Then to mount the remote drive you need to make a local empty directory - I call mine sc and it's located in my home directory. Then you mount the remote drive in the remote directory with

sshfs -o follow_symlinks <user>@<server address>:/ ~/sc

When you open sc with your favorite file explorer (such as Finder on MacOS) you'll find the remote drive there, probably with the name OSXFUSE Volume 0...

Hope this helps!

Solution 4

tiv (or similar tools) should do in most cases. This does not require any special terminal emulators since it only prints RGB ANSI codes.

enter image description here

Also supports wildcards.

Solution 5

This is a common pain point amongst computer vision researchers. I created a tiny script (https://github.com/nicodjimenez/ImgView) which I use to serve images in a directory on a remote machine via python run.py -d path/to/image/dir/. Then I use ssh tunneling to forward a local port to the remote port on which I am running the server, and then I just view the images on my local machine by pointing my web browser to my local port, by default http://0.0.0.0:8000/. This approach is the most flexible for viewing images over ssh because you can control the appearance of the display.

Share:
138,095

Related videos on Youtube

mrhobbeys
Author by

mrhobbeys

Updated on September 18, 2022

Comments

  • mrhobbeys
    mrhobbeys over 1 year

    I am monitoring a website and want to know if there is a way that I can view the pictures via ssh rather than loading the website each time.

    • Frank Thomas
      Frank Thomas about 11 years
      so you have ssh access to the server and are watching the images directory?
    • mrhobbeys
      mrhobbeys about 11 years
      Yes, I setup a scritp to alert me when something new is added. Now I want to be able to view it and remove or approve via ssh.
  • mrhobbeys
    mrhobbeys about 11 years
    This wouldn't really work well only because at that point it would be easier to open a browser to see them.
  • mrhobbeys
    mrhobbeys about 11 years
    I'm on windows with putty and xming today, so I am going to give this a try.
  • mrhobbeys
    mrhobbeys about 11 years
    This works nicely.
  • Frank Thomas
    Frank Thomas about 11 years
    or use WinSCP if on Windows.
  • nabisorry
    nabisorry about 11 years
    @FrankThomas: Well, that wasn't what I had in mind. With sshfs you can simply mount the remote file system and it will behave as if the files are on your computer. No need to download anything...
  • Andrew Hundt
    Andrew Hundt about 7 years
    What if you're on osx with iterm 2 and have used ssh to get into a remote machine?
  • Dyno Fu
    Dyno Fu about 7 years
    It will work if you have the imgcat script on the server.
  • crizCraig
    crizCraig almost 7 years
    Looks like the repo is down, but this can also be accomplished with the built in web server python -m SimpleHTTPServer. Also if your local machine and server are on a VPN, there's no need to ssh forward.
  • CousinCocaine
    CousinCocaine almost 6 years
    imgcat, wouldn't an image of a cat be more appropriate?
  • fabian789
    fabian789 over 4 years
    With python 3: python -m http.server. Will serve al files in current folder.
  • Sridhar Sarnobat
    Sridhar Sarnobat over 4 years
    Does the server have to be OS X? What exactly should I do if my server is Ubuntu and my client is Mac?
  • Dyno Fu
    Dyno Fu over 4 years
    there is no requirement on server. if you are ssh from the terminal, the server has to have imgcat. basically, imgcat convert the image to something iTerm2 can understand.
  • 0-_-0
    0-_-0 almost 4 years
    I had a system without a working eog, in that case feh img.png is a viable option, too
  • nikhilweee
    nikhilweee over 3 years
    I created another library called shis. It's similar to the one described by @nicodjimenez, except that it creates thumbnails of all image files and serves them in a nice gallery format. github.com/nikhilweee/shis
  • rii
    rii over 3 years
    And if you need to install imagecat on the server you just ssh(ed) to, like I just had to, you can run: sudo curl -o /usr/local/bin/imgcat -O https://iterm2.com/utilities/imgcat && sudo chmod +x /usr/local/bin/imgcat
  • Grifball
    Grifball over 2 years
    I use this method (using http.server) all the time and wanted to add that you should always use the --bind option to bind it to localhost (or 127.0.0.1) if you're viewing it over ssh as you can forward the port with the ssh argument: -Llocalhost:8000:localhost:8000. Otherwise, the http server will be available to any machine on the same network which you may not want. If you're ssh'd into a VPS or AWS, this could be the entire internet.
  • KenneyE
    KenneyE over 2 years
    For further info on iterm's shell integration, which allows you to use imgcat on a remote ssh session: iterm2.com/documentation-shell-integration.html
  • jave.web
    jave.web about 2 years
    On linux(ubuntu) there were some permission issues with reading, but it can be bypassed with cat and then use imgcat anyways: cat <image>.jpg | imgcat
  • Community
    Community about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • Admin
    Admin almost 2 years
    Gives a quick low-fi image preview but this seems to be a bomb-proof way that always works in any terminal. I did brew install tiv on my ubuntu 20.04 server.