Can't get VNC working: SSH connection refused

Posted October 28, 2014 16.5k views

Dear Digital Ocean community,

I’m a developer and I’m all kinda unexperienced to hosting/linux.
I know the basics of linux but that’s it.
For my latest school project, we are in need of a linux server.

I’m trying to get VNC working, and I followed both of these tutorials:

Problem is, when I arrived at the very last step of the second tutorial (Step Four — Connect to Your VNC Desktop), you should enter the following command:

ssh -L 5901: -N -f -l user server_ip_address

I get the following response:
ssh: connect to host “here comes my server ip” port 22: Connection refused

It is weird because in step 5 from the first tutorial, they told me to change this port 22 to another port.

I really hope someone can help me, because I’ve been struggling alot with my server lately. :(
Thanks in advance!


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Use the port you set when you followed the first tutorial.

ssh -L 5901: -N -f -l user -p your_port server_ip_address
  • Alright thanks alot. That did the trick for that command.
    Now when I try to connect to my_ip:5901 it’s still saying ‘The connection was refused by the host computer’.
    I’m using VNC Viewer, because PuTTy (the program they recommend in tutorial) doesn’t work on mac..

    God damn I’m always so close to the VNC connection. :/

  • If I understand it right. After you have made the ssh connection. You have to connect your vnc client to

    Here is the relevant section of the man page.

    -L [bind_address:]port:host:hostport
    Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the remote machine. Port forwardings can also be specified in the configuration file. IPv6 addresses can be specified by enclosing the address in square brackets. Only the superuser can forward privileged ports. By default, the local port is bound in accordance with the GatewayPorts setting. However, an explicit bind_address may be used to bind the connection to a specific address. The bind_address of “localhost” indicates that the listening port be bound for local use only, while an empty address or ‘*’ indicates that the port should be available from all interfaces.
  • Nope still not working.
    As you can see in this screenshot I’m still getting the ‘connection refused’ error, god damn.