58

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.

2
  • so you have ssh access to the server and are watching the images directory? Feb 26, 2013 at 13:46
  • 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
    Feb 26, 2013 at 14:04

18 Answers 18

49

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.

3
  • I'm on windows with putty and xming today, so I am going to give this a try.
    – mrhobbeys
    Feb 26, 2013 at 15:10
  • This works nicely.
    – mrhobbeys
    Feb 26, 2013 at 15:20
  • 1
    I had a system without a working eog, in that case feh img.png is a viable option, too
    – 0-_-0
    May 4, 2020 at 12:34
17

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

11
  • 2
    What if you're on osx with iterm 2 and have used ssh to get into a remote machine? Mar 21, 2017 at 22:20
  • 1
    It will work if you have the imgcat script on the server.
    – Dyno Fu
    Mar 21, 2017 at 22:25
  • 30
    imgcat, wouldn't an image of a cat be more appropriate? Jun 18, 2018 at 21:12
  • 1
    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.
    – Dyno Fu
    Sep 3, 2019 at 20:38
  • 2
    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
    – rii
    Dec 5, 2020 at 2:14
15

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!

2
  • osxfuse has been superseded by macfuse as of version 4.0.0. Aug 30, 2022 at 8:09
  • does it transfer all files or just their names and load the file on demand?
    – Ahmad
    Feb 6, 2023 at 9:11
10

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.

1
  • 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. Jun 8, 2022 at 1:19
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.

4
  • 1
    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.
    – crizCraig
    May 8, 2017 at 1:40
  • 1
    With python 3: python -m http.server. Will serve al files in current folder.
    – fabian789
    Aug 5, 2019 at 12:05
  • 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
    – nikhilweee
    Nov 18, 2020 at 3:57
  • 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.
    – Grifball
    Jan 4, 2022 at 19:44
4

On Linux you could redirect ssh output. With the help of an image viewer able to read from the standard input (see Is there an image viewer that takes images on STDIN? ) and the Unix Pipe |, I get:

ssh remote_host "cat /remote/path/to/image" | display

PS: this requires ImageMagick's display program on the local host. The command between quotes is executed by ssh on the remote host. Or for other image viewers (here Gnome eog image viewer):

FIFO=$(mktemp -u);
ssh remote_host "cat /remote/path/to/image" > "$FIFO";
eog  "$FIFO" && rm "$FIFO";
2

In general you may transfer the media data, e.g. images, to your local desktop or the ssh terminal itself if capable of displaying media:

  • XWindow forwarding: brings any desktop imageviewer application from the remote host to your display
  • sftp: any sftp-client transfers the media to your local desktop where you may launch an image viewer
  • ssh filesystem: a bit like sftp, but the remote filesystem is seamlessly integrated locally so local image viewers may launch
  • Or webbased: This terminal (like many others) is itself capable of displaying image data (the image data is "cat"ed !)

http://liftoffsoftware.com/Products/GateOne enter image description here

1

I use thunar (a file manager, also works with nautilus and probably others) to do this kind of stuff.

If you enter the address:

sftp://user@ip:port/

It will connect via ssh (optionally asking for a password/passphrase) and it will display the filesystem visually, where you can open the images with a viewer (eg. gpicview or eog, but I found eog to be slow in this case).

1

Visual Studio Code's SSH extension lets you view remote images in the editor. It's cross-platform and does not require a local X server.

1

So what worked for me, using mac as my local machine and AWS's EC2 as my server (Ubuntu OS) was the following:

  • Install the open source xQuartz application on your mac, you can find it here.
  • Launch the application xQuartz. This will open a terminal window.
  • Connect to your server using X11 forwarding: ssh -Y user@server or ssh -X user@server
  • Go to the directory on your server with the pictures
  • Open the picture you want with: xdg-open picture_name. This will open up a window on your mac with the image.
1

First, you can connect to the server via ssh.

$ ssh -Y [email protected]

Note the -Y option. This is important in all ssh connections you make until you reach the machine where the images are located. For instance, if you have to make two hops to reach the target machine, you've to use -Y switch that enables trusted X11 forwarding.

$ ssh -Y [email protected]
$ ssh -Y towerpc23

Then, cd into the directory where images are located and do:

$ cat icelandic_white_horse.jpg | display

After a few seconds, the image will be relayed back to your local PC. Please note that only one image can be displayed at a time (i.e., no batch displays)

0

If you have the path of the pictures you can like Frank Thomas said then you can download them and open them in a picture viewer via scp or maybe sftp if you have access. If you're using linux then do a wget on the pictures, but of course you can't open them in a shell, so downloading them is you best option if you are talking purely shell.

2
  • This wouldn't really work well only because at that point it would be easier to open a browser to see them.
    – mrhobbeys
    Feb 26, 2013 at 14:05
  • Well it depends on the setup, because if the picture names have a similar path and naming convention, then it could be scripted and turned into a cronjob.
    – MDMoore313
    Feb 26, 2013 at 14:22
0

You can also use sshfs, if you're under Linux.

2
  • or use WinSCP if on Windows. Feb 26, 2013 at 15:27
  • 1
    @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...
    – carlspring
    Feb 26, 2013 at 15:41
0

You can add a network storage in your systemfile explorer :

Adding a server

0

How to Install Eye of Gnome (eog):

  1. Open the Terminal (Shortcut: Ctrl + Alt + T)
  2. Type the following command: sudo apt-get update
  3. Press Enter or Return and type in your password
  4. Type the following command: sudo apt-get install eog
  5. Type Y and press Enter or Return

after install eog, use the below command :

ssh -Y user@server

eog pictures/yourimage.png

0

As @Paul was mentioning, the best way I have found is to use the built-in file explorer.

For instance, if using dolphin, one could run the command, which will open the file explorer, (may ask for password), and optionally, you can disown the process and close the terminal:

dolphin sftp://user@url & disown && exit

This way, you are able to browse files and open images on the local machine.

1
  • 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.
    – Community Bot
    Apr 14, 2022 at 8:25
0

Most of the high-rating answers require X11 forwarding or sftp, while I found a pure terminal method with Kitty and ranger. I used Mac OS as my desktop and Ubuntu 18.04 as a server. Just install ranger on Ubuntu and Kitty on MacOS, and these two are the only requirements. The installation and usage are as follows:

Mac ssh to Ubuntu 18.04

On Ubuntu

  • Install ranger pip install ranger-fm (ranger is installed at ~/.local/bin/ranger)
  • Edit ranger config file (~/.config/ranger/rc.conf)
set preview_images true
set preview_images_method kitty

On Mac

  • Install Kitty brew install kitty
  • In Kitty terminal, SSH to Ubuntu with kitty +kitten ssh <HOST>
  • Run ranger to preview images

(Copied from here)

If you are using Windows/Linux as an desktop, Kitty can also be installed on your desktop OS.

EDIT: Windows require WSL2 support.

1
  • if you get an error like "ssh can only run inside kitty window" you have to first open kitty and then use the above command inside the new terminal
    – fabmilo
    Dec 4, 2022 at 2:31
0
  • Step 1: ssh -Y user@server
    • This enables X11 over ssh, and then your local App, e.g. MacOS's XQuatz, can display images from server.
  • Step 2: On the server, if feh or eog gives you command not found. ImageMagick is another display tool easy to use.
    • sudo apt install imagemagick
    • display xx.png

You must log in to answer this question.

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