How to configure dropbox for multiple users on a headless Debian / Ubuntu server

There are numerous guides around to configure Dropbox on a headless Debian or Ubuntu server but it seems everytime I go to do one, I can’t find the nice guide I usually use or a website is down when I look for alternatives. So here is my quick guide for myself and anyone else that might stumble upon this page :)

For 32bit:

wget -O dropbox.tar.gz https://www.dropbox.com/download?plat=lnx.x86

tar xzf dropbox.tar.gz

./.dropbox-dist/dropboxd

For 64bit:

wget -O dropbox.tar.gz https://www.dropbox.com/download?plat=lnx.x86_64

tar xzf dropbox.tar.gz

./.dropbox-dist/dropboxd

At this point, dropbox will complain about not being linked to an account and output a web address to follow, do that and login to your account and it will be linked.

Kill the dropbox that you started manually (requires pgrep, if you don’t have it you can use your favorite method):

kill $(pgrep dropbox)

You can repeat the above steps for each user you want to have with their own dropbox.

For older versions of Debian pre-systemd: As root, either download this startup script or copy & paste the following code to /etc/init.d/dropbox and edit the DROPBOX_USERS line as needed:

# dropbox service
DROPBOX_USERS="user1 user2"

DAEMON=.dropbox-dist/dropboxd

start() {
    echo "Starting dropbox..."
    for dbuser in $DROPBOX_USERS; do
        HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
        if [ -x $HOMEDIR/$DAEMON ]; then
            HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $HOMEDIR/$DAEMON
        fi
    done
}

stop() {
    echo "Stopping dropbox..."
    for dbuser in $DROPBOX_USERS; do
        HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
        if [ -x $HOMEDIR/$DAEMON ]; then
            start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON
        fi
    done
}

status() {
    for dbuser in $DROPBOX_USERS; do
        dbpid=`pgrep -u $dbuser dropbox`
        if [ -z $dbpid ] ; then
            echo "dropboxd for USER $dbuser: not running."
        else
            echo "dropboxd for USER $dbuser: running (pid $dbpid)"
        fi
    done
}


case "$1" in
  start)
    start
    ;;

  stop)
    stop
    ;;

  restart|reload|force-reload)
    stop
    start
    ;;

  status)
    status
    ;;

  *)
    echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
    exit 1

esac

exit 0

After that, you need to make it executable and add it to system startup:

sudo chmod +x /etc/init.d/dropbox

sudo update-rc.d dropbox defaults

Repeat the starting, linking & killing steps above for all of the accounts you want to link. Once that is done run the dropbox init script you copied above:

sudo /etc/init.d/dropbox start

For newer Debian versions with systemd, create a file named /lib/systemd/system/dropbox@.service with the following content:

[Unit]
Description=Dropbox as a system service
After=local-fs.target network.target

[Service]
Type=simple
ExecStart=/usr/bin/env "/home/%i/.dropbox-dist/dropboxd"
Restart=on-failure
RestartSec=1
User=%i

[Install]
WantedBy=multi-user.target

After this, simply run

sudo systemctl enable dropbox@username

sudo systemctl start dropbox@username

And now you should be done. If you want to confirm that multiple dropbox accounts are running you can do:

ps aux | grep -i dropbox