How do I create a system-wide autostart file? This would be on a cloud server running the desktop version of Maverick.

I logged in as root and created an autostart file using System/Preferences/StartupApplications but it ended up in /root/.config/autostart and did not execute (as far as I can tell) upon rebooting. The autostart file is to invoke a bash script that invokes the VNC server.

I copied the .desktop autostart file from /root/.config/autostart to /etc/xdg/autostart and rebooted. This did not seem to make a difference.

Edit As mentioned in a comment, the objective is to run my bash script which starts the VNC server upon boot; not upon a login.

  • do you mean autostart on boot or autostart when someone (anyone) logs on?
    – fossfreedom
    Apr 11, 2012 at 10:37
  • I want the VNC server to autostart on boot.
    – H2ONaCl
    Apr 11, 2012 at 10:38
  • 1
    I've found an answer at SU SE superuser.com/questions/147109/… give it a try
    – wisemonkey
    Apr 17, 2012 at 17:35
  • Doesn't VNC requires a display to run?
    – desgua
    Apr 21, 2012 at 1:39

7 Answers 7

  1. First, install the TightVNC server sudo apt-get install tightvncserver.

  2. Set up the VNC server for the user you wish to log in as. When you run "vncserver" for the first time, it will ask you to set a password. only allow SSH tunnelled or VPN connections. To launch programs or a session when your VNC session starts, modify ~/.vnc/xstartup. Here is an example.

    xrdb $HOME/.Xresources
    xsetroot -solid black
    /opt/azureus/azureus &
    k3b &
    icewm-session &
  3. Copy the following into /etc/init.d/vncserver. The easiest way to do it is to copy it to your clipboard, run sudo -i && cat > /etc/init.d/vncserver && exit in a terminal, paste it in, and type CTRL-D. Be sure to change the USER variable to whatever user you want the VNC server to run under.

    #!/bin/sh -e
    # Provides:          vncserver
    # Required-Start:    networking
    # Default-Start:     3 4 5
    # 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
  4. Make the script executable with sudo chmod +x /etc/init.d/vncserver.

  5. Finally, connect to your server with a VNC client on port 590X, where X is the value of "DISPLAY" in the vncserver script. On OS X, I like to use Chicken of the VNC. On Windows and Linux, the TightVNC client works nicely.


  • This superuser.com/questions/147109/… from wisemonkey is the stackexchange equivalent answer. It works. Note the path to X11 might need adjusting.
    – H2ONaCl
    Jun 8, 2012 at 13:21
  • TigerVNC installs /etc/init.d/vncserver which starts all vncservers configured in /etc/sysconfig/vncservers
    – Kashyap
    Jul 28, 2014 at 15:01
  • 6
    This was copy-pasted from abdevelopment.ca/blog/start-vnc-server-ubuntu-boot, but it LEFT OUT THE MOST IMPORTANT STEP sudo update-rc.d vncserver defaults Sep 3, 2016 at 15:05
  • Since this solution is accepted, can you detail whether the described steps are "only allowing tunnel SSH or VPN connections" ? Or was this a prerequisite? @maniat1k13
    – Myoch
    Jan 28 at 11:34

One possibility: /etc/rc.local

The content says it:

# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits. 
# By default this script does nothing

The execution bits are set to 755 on my system already. (chmod 755 /etc/rc.local)

You can put any command in there, which will be executed as root.

This is ok for your purpose as long as you do not change runlevels, I guess. (If you do not know what runlevels are, nevermind).

  • 3
    This suggestion did not work for me.
    – H2ONaCl
    Apr 15, 2012 at 14:31
  • These 2 tweaks may help. May 11, 2012 at 7:57
  • @CeesTimmerman, thank you but those 2 tweaks did not work.
    – H2ONaCl
    Jun 8, 2012 at 12:51

this seems to be an old post but the topic might be still interesting for some users. To have vnc to start at boot up, you will need to

  1. install a vnc server software (here we will be using x11vnc)
  2. configure a startup script (used to start the vnc service)

Step 1 - install x11vnc server

from a command line, type

 sudo apt-get install x11vnc

To add security, you should set a pwd

sudo x11vnc -storepasswd

Step 2 - Configure your startup script

  • if your ubuntu version is lower 15.04,

you create the config file under /etc/init.d/x11vnc.conf and populate it with the correct commands to be executed

start on login-session-start  
/usr/bin/x11vnc -xkb -auth
-noxrecord -noxfixes -noxdamage 
-rfbauth /etc/x11vnc.pass 
-forever -bg -rfbport 5900 -o /var/log/x11vnc.log  
end script
  • if your ubuntu version is 15.04 or later,

these systems are using systemd and you will need to create your service unit file under /lib/systemd/system/x11vnc.service and populate it with the correct commands to be executed

[Unit] Description=Start x11vnc at startup. After=multi-user.target

[Service] Type=simple ExecStart=/usr/bin/x11vnc -auth guess -forever
-loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared

[Install] WantedBy=multi-user.target

Reload the service

sudo systemctl daemon-reload

sudo systemctl enable x11vnc.service

You can find detailed information on Help Ubuntu Community wiki page (see here) or you can try to use this quick to use recipice

  • For Ubuntu version lower than 15.04, check this post
  • For Ubuntu version 15.04 or later, check this post

Hope this is helpful


If you're using TigerVNC then it installs /etc/init.d/vncserver which starts all vncservers configured in /etc/sysconfig/vncservers E.g. following would start 2 instances on display 1 & 2 at start up.

# <display>:<user>
VNCSERVERARGS[1]="-geometry 1920x1080"

VNCSERVERARGS[2]="-geometry 800x600 -SecurityTypes None"

Add the below line to crontab file. This means the command after the keyword @reboot gets executed during very reboot.

@reboot /usr/bin/vncserver :1

To open crontab file, need to use the command crontab -e


You can have cron start stuff for you at boot time. Just use the string "@reboot" in place of the numbers that you normally use to specify when the thing should run.

For example, here's how I start Dropbox on a machine on which it doesn't otherwise start automatically:

# m h  dom mon dow   command
@reboot         /usr/bin/dropbox start
  • This page says that only works if the system actually reboots (no cold boot). May 11, 2012 at 7:52

'sudo update-rc.d vncserver defaults' reported that there was missing; "Required-Stop:" (even empty). So I added it like below. And no more warning.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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