I installed the Ubuntu desktop on a Ubuntu 9.10 VPS server and am able to connect to the server using TightVNC. However, the VNC server on this VPS can only be started by logging in through SSH and typing the following command:

vncserver :1 -geometry 800x600 -depth 16 -pixelformat rgb565

If I run this command on startup or as a schedule task, it won't start. What are my options?

  • Have you tried to figure out why it won't start? May 31, 2010 at 2:45
  • I had the same problem. I added >>/tmp/vnc-startup-error 2>&1 behind the command and found the error message in /tmp/vnc-startup-error. Turns out vncserver expects a variable USER to contain the user name. With it set, it works now. Mar 12 at 19:44

7 Answers 7


I found these instructions by searching Google for "ubuntu launch vnc server on startup".

  1. Install the VNC server.
  2. Launch vncserver for the first time to set up a password.
  3. Add the following file as /etc/init.d/vncserver (be sure to modify the USER, GEOMETRY, NAME, etc. to your liking).
  4. sudo chmod +x /etc/init.d/vncserver
  5. sudo update-rc.d vncserver defaults


#!/bin/sh -e
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     S
# Default-Stop:      0 6


# The Username:Group that will run VNC
export USER="mythtv"

# The display that VNC will use

# Color depth (between 8 and 32)

# The Desktop geometry to use.

# The name that the VNC Desktop will have.

OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"

. /lib/lsb/init-functions

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

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

$0 stop
$0 start

exit 0
  • I'm getting the following error output gist.github.com/anonymous/821d0ec525abb2fe42d8a070c846fb9e, I believe your configuration needs updated with some blank values.
    – user788072
    Oct 27, 2017 at 9:31
  • mine works but the only issue is that it asks for my to enter a password in order to start the script for the first time. since its on boot i cant enter it. how can i fix it?
    – droopie
    Feb 20, 2018 at 2:27
  • @droopie have you found a solution for the password?
    – bomben
    Sep 23, 2019 at 8:08

If you want a more dynamic configuration and the ability to connect for multiple users then there is a better way to do this. As root create the file (and directory if it doesn't exist) /etc/sysconfig/vncservers i.e. do:

mkdir -p /etc/vncserver
touch /etc/vncserver/vncservers.conf

Add servers as needed for each user by adding something like the following to the vncservers.conf file you just created:

VNCSERVERS="1:justin 2:bob"
VNCSERVERARGS[1]="-geometry 1920x1080 -depth 24"
VNCSERVERARGS[2]="-geometry 800x600 -depth 8"

next create an empty init script and make it executable:

touch /etc/init.d/vncserver
chmod +x /etc/init.d/vncserver

add the following to /etc/init.d/vncserver:


[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$"VNC server"

start() {
        . /lib/lsb/init-functions
        echo -n $"Starting $prog: "
        ulimit -S -c 0 >/dev/null 2>&1
        for display in ${VNCSERVERS}
                export USER="${display##*:}"
                if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
                        echo -n "${display} "
                        unset BASH_ENV ENV
                        export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
                        su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"

stop() {
        . /lib/lsb/init-functions
        echo -n $"Shutting down VNCServer: "
        for display in ${VNCSERVERS}
                export USER="${display##*:}"
                if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
                        echo -n "${display} "
                        unset BASH_ENV ENV
                        export USER="${display##*:}"
                        su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
        echo -e "\n"
        echo "VNCServer Stopped"

case "$1" in
start $@
stop $@
stop $@
sleep 3
start $@
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
status Xvnc
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1

As Stephen mentioned in his answer you'll need to run vncserver AT LEAST ONCE AS EACH USER you want to login as. I put that in caps because if you skip that step none of it will work. So as root you could do:

su justin -c vncserver
su bob -c vncserver

This will create a .vnc directory in each users home dir with the appropriate startup scripts.

Finally, do the following:

update-rc.d vncserver defaults 99

now you can either reboot or start the service manually by typing:

service vncserver start
  • 2
    this actually works for me but the only thing is that it doesnt quite start it automatically i think because it might be requesting the user password. since its automatically triggered, i do not see it ask for it. if i manually launch the script, it asks for a my user password. how can i fix this?
    – droopie
    Feb 20, 2018 at 2:25
  • 2
    Doesn't work. I can't connect. Boy, Linux is really making want to run back to Windows and embrace it like an old lover. I have never before seen a platform where 100% of the "help" you can find on the web simply doesn't work and gives random errors that you're never told how to deal with. Not 99%, 100%. "Job for vncserver.service failed because the control process exited with error code."
    – John Smith
    May 25, 2020 at 21:46
  • Ack, I didn't see the date on the post. Jeezm I wish SE would mark ancient answers more clearly... this is 8 years old, obviously it's not going to work anymore.
    – John Smith
    May 25, 2020 at 22:01
  • I don't get it. People who create such complex software cannot manage to make it just work in most popular distribution... Seriously, there is no application for desktop to configure this?
    – Kamil
    Jan 24 at 15:27
  • @droopie; You need to ask each user to login to the system once (they can use ssh if systems are at remote location) and then ask them to run this command vncpasswd passwd and set the password. This will create a file /home/droopie/.vnc/passwd. This file will be used by the script in the answer.
    – haccks
    May 3 at 18:44

In Ubuntu 12.1 I was able to go into System Settings->Users and select a user and set "Automatic Login->ON"

Then I was able to use tightVNC to get in without logging in to the box itself.

Worked well for headless ubuntu linux box

  • 1
    From what I can gather, the question is about powering up vncserver on startup, not user login. Mar 15, 2017 at 9:55
  • At the end, this is the least complicated solution if you can afford it
    – brasofilo
    Mar 22, 2020 at 6:00

I access the Ubuntu of friends I help, to install or configure or to teach them something.
As I need access from the Internet through the modem, I use vino.
All sharing and Security options are turned on during access.
I don't want the vino-server to be active all the time: it's just fine it doesn't autostart.
I had no System>Remote Desktop menu.
I edited /usr/share/applications/vino-preferences.desktop as follows:

# OnlyShowIn=Unity;
Exec=bash -c 'vino-preferences;/usr/lib/vino/vino-server&zenity --info --text="Accès par Internet: `curl http://ipecho.net/plain`:5900"'

Before work, I ask my friends to run Remote Desktop Preferences and to tick Sharing Allow... on.
On exiting Preferences, vino-server starts and they tell me the IP address to use.
When work is finished, they run Preference again to tick Sharing Allow... off.
On exiting Preferences, vino-server stops and would stop even if started in Sharing off state.
I find this procedure very convenient as well as the safest for the user.

PS: developers prefer their programs to run locally (within a user session) because a bug cannot affect the global system that way.


I suggest to use stephen jennings solution also if you need several vnc's for different users, by just creating several vncserver_john, vncserver_bill, ... files. This allows you to start/stop them separately. Certainly, good programming practice suggests to put the code common to all users into one file, and source it from all others.

I have "inherited" responsibility for a server where several colleagues do some scientific programming and data evaluation, everybody with a separate vnc. The server actually runs continuously and stable over years, and users become lazy to save their open windows. However, single vncservers or X11 servers sometimes become stuck, and it is a big nuisance to shut down all users to get one server running again.


I got it auto-starting on boot by entering this into /etc/crontab:

@reboot  thorsten USER=thorsten /usr/bin/vncserver >>/tmp/vnc-startup-error 2>&1

This means:

@reboot - execute this at reboot

thorsten - as the OS user thorsten. Replace by your user!

USER=thorsten - part of the command to execute, sets the USER environment variable. Replace by your user!

/usr/bin/vncserver - what to start

>>/tmp/vnc-startup-error 2>&1 - log standard output and error output to the file /tmp/vnc-startup-error


Ok I did get it running as described above without Thorsten's add but I think his way works too. But there is one error listed above. Runlevels are wrong.


update-rc.d -f vncserver defaults

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.