DigitalOcean is one of the hottest new kids in the block in the cloud VPS hosting market. While not offering as comprehensive service portfolio as Amazon Web Services and the likes, DigitalOcean is already a strong contender for the best Linux-based cloud VPS service targeted at small businesses and developers, thanks to their competitive pricing and user-friendly management interface.
Whenever you need a web-facing server for your personal project, you can quickly spin up a "droplet" (nickname for a VPS instance at DigitalOcean). And kill it when it's not needed. No need to burn a hole in your pocket as you are charged for its up time. While DigitalOcean's web-based management interface is streamlined already, for those of you who are die-hard fans of command-line interface (CLI), there is a CLI-based droplet management tool called Tugboat. Thanks to this CLI tool, any complex droplet management task can easily be turned into a script.
In this tutorial, I am going to describe how to use Tugboat to manage DigitalOcean dropets from the command line.
Install Tugboat on Linux
To install Tugboat on Debian, Ubuntu or Linux Mint:
$ sudo gem install tugboat
To install Tugboat on Fedora:
$ sudo gem install tugboat
To install Tugboat on CentOS, first install or upgrade to the latest Ruby, because on CentOS 6.5 and earlier, the default Ruby does not meet the minimum version requirement (1.9 and higher) for Tugboat. Once you install Ruby 1.9 and higher, install Tugboat as follows.
Configure Tugboat for the First Time
After installation, it's time to go through one-time configuration, which involves authorizing Tugboat to access your DigitalOcean account.
Go to https://cloud.digitalocean.com/api_access, and create a new API key. Make a note of client ID and API key.
Start authorization process by running:
When prompted, enter your client ID and API key. It will ask you several other questions. You can accept default answers for now. We are going to customize the default settings later anyway.
Now let's customize default droplet settings to reflect your typical use cases. For that, first check available droplet offerings (e.g., available images, regions, sizes).
Running the command below will show you a list of available droplet images. Pick a default image to use, and make a note of the corresponding ID.
Similarly, pick a default geographic location from available regions:
Also, choose a default droplet size from available RAM sizes:
Now put your default choices in ~/.tugboat. For example, here I customize my default settings to 512MB Ubuntu 14.04 x64 to be created in New York region. Set "ssh_user" to root if you want to enable SSH via key authentication, which will be described shortly.
--- authentication: client_key: XXXXXXXXXXXXXXXXXXX api_key: XXXXXXXXXXXXXXXXXXXX ssh: ssh_user: root ssh_key_path: /home/dev/.ssh/id_rsa ssh_port: '22' defaults: region: '4' image: '3240036' size: '66' ssh_key: '' private_networking: 'false' backups_enabled: 'false'
Create and Add SSH Key to DigitalOcean
A secure way to access your droplet instance is to SSH to the instance via key authentication.
In fact, you can automatically enable key authentication for your droplets by registering your SSH public key with DigitalOcean. Here is how to do it.
First, generate a private/public SSH key pair (if you don't have one).
Assuming that the generated key pair consists of: ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key), go ahead and upload your public key by running:
You can give your key any name you like (e.g., "my-default-key"). When prompted, enter the path to your public key (e.g., /home/user/.ssh/id_rsa.pub). After key uploading is completed, verify the key is successfully added by running:
The key should also appear in DigitalOcean's SSH key page. If you want the key to be automatically used for your droplets, add the ID of your key to ~/.tugboat.
Basic Usage of Tugboat
Here are a few basic use cases of tugboat command line.
1. Create a new droplet with default settings.
2. Show a list of all active droplets.
3. Display information about a droplet.
4. Shutdown a droplet, and remove its image.
5. Shutdown a droplet, but keep its image
6. Take a snapshot of a droplet. The droplet must be turned off first.
7. Resize (increase or decrease the RAM size of) a droplet. The droplet must be shutdown first.
If you want to know more about a particular command option, run:
1. When I run tugboat command, it fails with the following error.
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': /usr/lib/ruby/gems/1.8/gems/tugboat-0.2.0/lib/tugboat/cli.rb:12: syntax error, unexpected ':', expecting kEND (SyntaxError)
Tugboat requires Ruby 1.9 and higher. You need to upgrade Ruby to solve this problem. For CentOS, refer to this tutorial.
2. When I try to install Tugboat with gem, I get the following error.
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- json/pure (LoadError)
Install the following gem to fix the problem.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!