0

I've followed the instructions here to set up a vncserver service: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-14-04

I only used the section on setting up the vncserver service since I already had vnc4server installed.

Options for starting vncserver:

  1. Use the service I created by running: sudo service vncserver start/stop/restart. It works fine and kicks of the Xvnc4 process.
  2. Simply type vncserver into the terminal.

In both cases, I have double checked that the Xvnc4 service associated with vnc4server is started and running using ps -aux | grep vnc.

In both cases, a display is created and attached to display 1.

My problem: When I use option 1 to start my vncserver, I am unable to connect to the display created from my windows pc using vncviewer.

When I use option 2, I am able to connect to the display from my windows pc using vncviewer. I simply provide serverip:<display#>.

Why can't I connect when I use option 1. Also, is the suggestion to setup a secure tunnel using something like putty and then connecting through it just for security? I ask because when I start my vncserver using option 2 above, I'm able to connect remotely using servername or ip:display# without using putty or any kind of tunnel.

Here is my ~/.vnc/xstartup:

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

Here is my /etc/init.d/vncserver service file:

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="mo"
DISPLAY="1"
DEPTH="16"
#GEOMETRY="1024x768"
#GEOMETRY="1600x1200"
GEOMETRY="1366x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"
. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac
exit 0
7
  • Since the /etc/init.d/vncserver file includes option -localhost, you will need to tunnel the connection as indicated i.e. ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address. See for example vncserver -localhost and ssh tunneling Dec 27, 2017 at 23:42
  • So where do I input the command ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address? In putty settings? Or on a ssh session I connect to through putty?
    – mo_maat
    Dec 27, 2017 at 23:50
  • Ok. I got it to work. Thanks for the pointer. I had my putty tunnel setup wrong. I was using the remote server address instead of localhost. But I still want to know how I can connect to more than one vnc display so I can work across two monitors? I'm guessing I have to set up a second tunnel?
    – mo_maat
    Dec 27, 2017 at 23:56
  • I think I figured it out. I should be able to set up more than one tunnel on my putty connection and connect using different ports. I just need to figure out how the use my vncserver service to start another display on my server.
    – mo_maat
    Dec 28, 2017 at 0:09
  • Problem solved. I was able to edit my vncservice to start multiple displays.
    – mo_maat
    Dec 28, 2017 at 1:00

1 Answer 1

1

Thanks to steeldriver's pointers, my problem was that my settings in putty on my pc were wrong. I was using my remote server address rather than using "localhost". To address my need for two displays, I set up two different tunnels in putty under the same connection:

localhost:5901

localhost:5902

I then modified my /etc/init.d/vncserver to start two instances of vncserver on two different displays.

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="mo"
DISPLAY="1"
DISPLAY2="2"
DEPTH="16"
#GEOMETRY="1024x768"
#GEOMETRY="1600x1200"
GEOMETRY="1366x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"
OPTIONS2="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY2} -localhost"

. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"


log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver ${OPTIONS2}"

;;

stop)
log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"


log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISP$
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY2}"

;;

restart)
$0 stop
$0 start
;;
esac

I was then able to use vncviewer on my windows pc to connect to display 1 and display two, hence somewhat mimicking a dual screen setup. It works for me. If anyone has any warnings or insight on why this shouldn't be done I would be happy to get the feedback.

You must log in to answer this question.

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