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

Give your user sudo privileges

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.

  1. From the terminal (you’ll have to secure shell to the server, since this is headless), gain root privileges with the su command.
  2. Issue the command gpasswd -a USER wheel (USER is the name of the actual user that needs sudo privileges).

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)

Download, unpack, install

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.

Controlling Dropbox

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.

  1. Create a script called dropbox.service with the contents from GitHub.
  2. Move that file with the command sudo mv dropbox.service /etc/systemd/system/
  3. Create a script called dropbox with the contents from GitHub.
  4. Move that file with the command sudo mv dropbox /etc/init.d
  5. Give those scripts executable permission with the command sudo chmod +x /etc/systemd/system/dropbox.service /etc/init.d/dropbox

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:

  • status get current status of dropboxd
  • throttle set bandwidth limits for Dropbox
  • help get help
  • puburl get a public url of a file in your Dropbox public folder
  • stop stop dropboxd
  • running show if Dropbox is running
  • start start dropboxd
  • filestatus get current sync status of one or more files
  • ls list directory contents with current sync status
  • autostart automatically start Dropbox at loing
  • exclude exclude a directory from syncing
  • lansync enables/disables LAN sync
  • sharelink get a shared link for a file in Dropbox
  • proxy set proxy settings for Dropbox

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.

Subscribe to the Cloud Insider Newsletter

This is your go-to resource for the latest news and tips on the following topics and more, XaaS, AWS, Microsoft Azure, DevOps, virtualization, the hybrid cloud, and cloud security. Delivered Mondays and Wednesdays

Subscribe to the Cloud Insider Newsletter

This is your go-to resource for the latest news and tips on the following topics and more, XaaS, AWS, Microsoft Azure, DevOps, virtualization, the hybrid cloud, and cloud security. Delivered Mondays and Wednesdays