enable vnc over ssh

Hi everyone,


I am struggling over how to set up vnc over a ssh connection on my local Mac. I can connect a ssh to the remote host but it is only command-line-based. I prefer visualization so I want a vnc. I have googled a lot of pages on how to enable a vnc over ssh and most of them suggest that I first key in "ssh -L 5901:localhost:5901 -N -f -l username remote_IP" on a terminal and give the password when prompted. Then key in "vncviewer localhost" will suffice. But what is this "vncviewer"? My laptop denotes there is no such command...

Posted on Sep 8, 2017 1:43 PM

Reply
3 replies
Sort By: 

Sep 9, 2017 4:44 PM in response to BobHarris

Hello,


Thank you for your reply! I have followed your suggestion to change remote port to 5900. My command line to set up ssh tunnel is now as following:

ssh -L 5900:localhost:5900 -N -f -l username remote.system.address


Then I go to Finder -> Go -> Connect to Server -> vnc://localhost:5900 but there is a wrong message:User uploaded file

In the meantime, the terminal shows that "channel 2: open failed: connect failed: Connection refused". What is "channel 2" here? How can I solve this?

Reply

Sep 9, 2017 5:02 PM in response to wen137

open vnc://localhost:5901

Or

Finder -> Go -> Connect to Server -> vnc://localhost:5901


This will start up the macOS build-in Screen Sharing app, which support VNC, and should do exactly what you want. Especially if the other system is a Mac.


NOTE: Is your remote VNC server running on port 5901? I ask, because typically VNC servers use port 5900. I would have expected to see an ssh command more along the lines of:

ssh -L 5999:127.0.0.1:5900 -N -f -l username remote.system.address

Where the 5999 is the local port (could be any unused port), 5900 is the VNC server port on the remote system, and the command to make your connection would be "open vnc://localhost:5999"


If you are NOT going to another Mac, but rather going to a Linux or Unix based system, then download and install the free RealVNC Viewer. This will perform better in a cross platform environment.

<https://www.realvnc.com/en/connect/download/viewer>

I find the nicest thing is that RealVNC keeps your clipboard in sync, so that you can Copy & Paste between the 2 systems.


Re: vncviewer is an open source app. It is also X11 based. To use vncviewer you would have to

A) get it via a package manager (or compile it yourself)

B) install XQuartz to get X11 support on your Mac

C) it would be a less pleasant experience. 🙂


PS. I do VNC across ssh tunnels all the time. I connect to my Mom's 300 mile away iMac using an ssh tunnel. When connecting from home to work and I want to use a VNC, I use an ssh tunnel.


PS 2. I have used vncviewer in an X11 environment on my Mac, so I speak from experience. The macOS Screen Sharing, RealVNC, or Chicken (of the VNC), would all be better than using vncviewer.

Reply

Sep 10, 2017 8:49 AM in response to wen137

In the meantime, the terminal shows that "channel 2: open failed: connect failed: Connection refused". What is "channel 2" here? How can I solve this?

I'm guessing the SSH connection has multiple channels, and the tunnel is channel 2.

Connection falied to "localhost"

I'm going to guess that 5900 is not the port the remote VNC server is listening on. Maybe it is 5901. We are going to have to figure this out.


Time to ask a few questions.

  • What operating system is the remote system using? Mac? Linux? Other?
  • Can you VNC without ssh?
    • If you can VNC without ssh
      • what is the VNC client you are using on your Mac?
      • what is the connection information (do not actually tell me the real remote host name or IP address; I do not need that, but I do need to know if you have to plug in a display number or port value)
    • If you CANNOT VNC without ssh, can you tell me anything about the VNC server you are using on the remote system
      • How do you start the remote VNC server? Did it come with the remote operating system, or did you have to install it?
      • Did you have to configure the remote server. Did you have to specify a display or port number. For example on a Linux system I use, I issue the following command to start my VNC server
        • vncserver :51
        • where :51 translates to port 5951, I would use: ssh -L 5999:localhost:5951 ...
        • did you need to use something similar to start your VNC server?
      • With your vnc server running on the remote system, assuming it is some flavor of Linux/Unix, can you get any information using the 'ps' command
        • ps ax | grep vnc
        • I get something like this from my Linux system:

          7851 ? S 14:18 /usr/bin/Xvnc :51 -desktop remote.node.name:51 (me) -rfbport 5951

      • If you have not figured out what the VNC server port is yet, is there an 'lsof' command (list output files)
        • lsof | grep 'vnc.*listen'
        • I get something like this:
          • Xvnc 7851 me 0u IPv6 602312 0t0 TCP *:6051 (LISTEN)
          • Xvnc 7851 me 1u IPv4 602313 0t0 TCP *:6051 (LISTEN)
          • Xvnc 7851 me 6u IPv4 602318 0t0 TCP *:5951 (LISTEN)
          • vino-serv 7926 me 15u IPv6 602922 0t0 TCP *:vnc-server (LISTEN)
        • The 5951 is the one I'm interested in.

Anything else you can tell me about the remote server, the remote operating system, etc... will be helpful in figuring out what is missing in the ssh connection setup.

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

enable vnc over ssh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.