In this tutorial, we will show you how to install the Dropbox client on an Ubuntu 14.04 server and configure it to run as a headless service. This will allow your server to connect to Dropbox so that you can sync copies of Dropbox files on the server.
You must have a non-root user (sudo
) with super user privileges. Students who don’t have a server can buy from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then buy server. All the commands in this tutorial will be executed as this non-root user.
Once ready, we will install the Dropbox client.
You can use the following command to download the latest version of the Linux Dropbox client to your home directory:
cd ~
curl -Lo dropbox-linux-x86_64.tar.gz https://www.dropbox.com/download?plat=lnx.x86_64
Now you will call a file named dropbox-linux-x86_64.tar.gz
in the home directory.
**Note: **If you are running a 32-bit distribution, please use this command instead of downloading a 32-bit Linux client:
cd ~
curl -Lo dropbox-linux-x86.tar.gz https://www.dropbox.com/download?plat=lnx.x86
Next, use the following command to extract the contents of the Dropbox archive to /opt/dropbox
:
sudo mkdir -p /opt/dropbox
sudo tar xzfv dropbox-linux-x86_64.tar.gz --strip 1-C /opt/dropbox
The Dropbox client is now on your server, but you need to associate it with your Dropbox account.
To link the Dropbox client with the Dropbox account, run this command (as the user who wants Dropboxfile storage in their home directory):
/opt/dropbox/dropboxd
This will launch the Dropbox client in the foreground, so you cannot enter any other commands at this time. When you run the client for the first time, you should see output like the following:
Host ID Link:This computer isn't linked to any Dropbox account...
Please visit https://www.dropbox.com/cli_link_nonce?nonce=ac8d12e1f599137703d88f2949c265eb to link this device.
Visit the URL in the output (highlighted in the example above) in a web browser on your local computer.
Log in to Dropbox (if you are not already logged in), and click the connect button:
After seeing the success message in the web browser, you should see this output on the Ubuntu server:
Link success output:This computer is now linked to Dropbox. Welcome Sammy
Now your Dropbox account has been linked with the client. You should now have a directory called "Dropbox" in your home directory. This is where the synchronized Dropbox files are stored.
**Press Ctrl-C to exit and pause Dropbox. **
The next step is to set up some scripts so that Dropbox runs as a service so that you don't need to log in to keep the client running.
To start Dropbox as a service, you need to create a script. To save trouble, you can use this command to download it to /etc/init.d/dropbox
:
cd ~
sudo curl -o /etc/init.d/dropbox https://gist.githubusercontent.com/thisismitch/d0133d91452585ae2adc/raw/699e7909bdae922201b8069fde3011bbf2062048/dropbox
Next, use the following command to make the script executable:
sudo chmod +x /etc/init.d/dropbox
The script expects the /etc/default/dropbox
file to contain a list of system users that will run Dropbox. Use the following command to create a file and open it for editing:
sudo nano /etc/default/dropbox
Add a line and specify that the line DROPBOX_USERS
is equal to your system username. For example, if your username is "sammy", it should look like this:
DROPBOX_USERS="sammy"
Save and exit the file by pressing Ctrl-x
, then y
, then Enter
.
Now, Dropbox is ready to start as a service. Run this command to start it:
sudo service dropbox start
Then run this command to configure the service to start when the server boots:
sudo update-rc.d dropbox defaults
Now, the Dropbox client runs as a service and automatically starts when the server starts.
Dropbox also includes a command line interface (CLI) that you may want to install so that you can configure the Dropbox client.
To download it to your home directory, run the following command:
cd ~
curl -LO https://www.dropbox.com/download?dl=packages/dropbox.py
Now, there will be a file called dropbox.py
Dropbox CLI in your home directory.
Use this command to make it executable:
chmod +x ~/dropbox.py
Then, in your home directory, create a symbolic link named .dropbox-dist
pointing to the installation path of Dropbox. This is necessary because the Dropbox CLI expects ~/.dropbox-dist
to contain your Dropbox installation:
ln -s /opt/dropbox ~/.dropbox-dist
Now you can run the Dropbox CLI from the home directory with the following command:
~ /dropbox.py
This will print out a basic help page. The next section will introduce how to use the Dropbox CLI to perform some basic operations.
Remember to run the CLI without any options and print out how to use it.
If you want to check the status of Dropbox, use the following status
command:
~ /dropbox.py status
If all files are synchronized, you should see the following message:
Up to date
You can also use it to turn off the automatic LAN synchronization function, which will try to synchronize related files on the LAN:
~ /dropbox.py lansync n
Another convenient command is exclude
. This will allow you to specify files and directories that should not be synchronized on the server. For example, if you don't want the server to download the photos
directory from Dropbox, you can run the following command:
~ /dropbox.py exclude add ~/Dropbox/photos
Then, you can verify which files and directories are excluded from the server using the following command:
~ /dropbox.py exclude list
Feel free to play with CLI and see what else you can do.
If you want to link more Dropbox accounts, please follow this section.
You can link multiple Dropbox accounts to your server. However, you need to use another system user for each Dropbox account you want to link.
After obtaining the system user account to be used, log in to the server as that user.
Run /opt/dropbox/dropboxd
. As before, this will output a URL to link the Dropbox account to the server.
Log in to Dropbox under the account you want to link to the server. Then visit the URL on the server and click the "Connect" button.
Next, edit /etc/default/dropbox
:
sudo nano /etc/default/dropbox
Add the new system user to the Dropbox user list. For example, if you have two system users running Dropbox, "sammy" and "ben", it looks like this.
DROPBOX_USERS="sammy ben"
Save and exit the file by pressing Ctrl-x
, then y
, then Enter
.
Now restart the Dropbox service:
sudo service dropbox restart
Your server is now linked to multiple Dropbox accounts.
To use the CLI on a new user, please make sure to follow the Install Dropbox CLI section again as the new user.
If you want to unlink your Dropbox account, please follow the steps below.
First, stop the service:
sudo service dropbox stop
Then edit /etc/defaults/dropbox
and delete the user from the list.
Then delete the user's Dropbox directory. E.g:
sudo rm -r ~/ben/Dropbox
Then, if your server is still linked to other Dropbox accounts, please start the Dropbox client again:
sudo service dropbox start
Finally, if you want to completely restrict access, you can go to the Dropbox Account Security Page and delete any linked devices.
The Dropbox client is now installed and running on your server. Your server should now be associated and synchronized with your Dropbox account.
For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.
Reference: "How To Install Dropbox Client as a Service on Ubuntu 14.04"
Recommended Posts