If you have a headless Linux server that needs access to files from a Dropbox account, here’s what to do.
There may come a time when you need to sync a Dropbox account to a Linux server running without a GUI. When that time comes, you’ll be glad that it’s pretty easy to do with the help of a few scripts.
I’ll walk you through the process of getting Dropbox up and running on a headless CentOS 7 server. This will be done entirely through the command line, so get your fingers ready to type.
SEE: The first five Linux command-line apps every admin should learn
Before we move on with the Dropbox installation, you’ll want to give your user sudo privileges. Out of the box, CentOS doesn’t add users to sudo, so you have to do it manually. Follow these steps.
Your user can now work with the sudo command. Exit out of the su user prompt, with the command exit, and get ready to work.
SEE: Linus Torvalds reveals his favorite programming laptop (ZDNet)
The first thing you must do is download the official Dropbox client. To do this, go to the terminal window and issue the command (from your user’s home directory):
curl -Lo dropbox-linux-x86_64.tar.gz https://www.dropbox.com/download?plat=lnx.x86_64
Once the file has downloaded, unpack it in your user’s home directory with the command tar xvzf dropbox-linux-x86_64.tar.gz.
To link Dropbox to your account, issue the command ~/.dropbox-dist/dropboxd. Note: The user who runs the dropboxd command will have the contents of the Dropbox account synced in their home directory.
When you run that command for the first time (and because you’re running Dropbox without a GUI), you’ll be presented with a link. Copy/paste that link into a browser and then either create a new account or log in to your existing account (when prompted) to add your server. Dropbox will automatically create the sync folder in the user’s home directory (on the server), and you’re almost good to go.
Unfortunately, the Dropbox client you downloaded doesn’t have the means by which you can control the service. For that, you need to take care of a few things.
First, set up Dropbox to run as a service. To handle that, do the following.
Now you must create a new file with the command nano /etc/sysconfig/dropbox with the following contents (USER is the actual name of the system user–not the Dropbox account user–that will sync to the Dropbox account).
DROPBOX_USERS=”USER”
Save and close that file.
Reload systemd with the command sudo systemctl daemon-reload and then start Dropbox with the command sudo systemctl start dropbox. To ensure Dropbox runs at boot, issue the command sudo systemctl enable dropbox.
Now we have to actually gain access to a Dropbox command line interface. To do that, download this Python script with the command:
curl -LO https://www.dropbox.com/download?dl=packages/dropbox.py
Give that file executable permissions with the command chmod +x dropbox.py.
At this point you can issue the command ./dropbox.py status to see if Dropbox is running. The possible command options for the dropbox CLI are:
Dropbox is now syncing on your headless Linux server. You can gain quick access to necessary files by dropping them into your Dropbox account, and they will then sync to your headless server.