Linode Library Home
Linode Library RSS Feed
Home
Print View View Source

Linode CLI

Published: by

The Linode Command Line Interface (CLI) is an open-source command line tool for managing your Linode services. You can reboot your Linode, update an MX record for your domain, manage your NodeBalancers, create a StackScript and more from the command line on any computer, without logging in to the Linode Manager graphical user interface.

Your Linode API key is required for the CLI to function.

Contents

Installing the CLI

You can install the Linode CLI on any Mac OS X or Linux computer. You can install it on a Linode if you want to, but the typical use case for the CLI is to run it from your home or office workstation. You can use it to manage your Linode account quickly, without the use of a GUI.

Mac OS X

In this section, you will learn how to install the Mac OS X package for the Linode CLI.

Prerequisites:

First, update Homebrew:

brew update

Run the following commands to install the Linode CLI:

brew tap linode/cli
brew install linode-cli

Debian and Ubuntu

In this section, you will learn how to install the Debian and Ubuntu package for the Linode CLI.

  1. Add the Linode repository to your list:

    sudo bash -c 'echo "deb http://apt.linode.com/ stable main" > /etc/apt/sources.list.d/linode.list'
    
  2. Get the Linode GPG key:

    wget -O- https://apt.linode.com/linode.gpg | sudo apt-key add -
    
  3. Update your system:

    sudo apt-get update
    
  4. Install the Linode CLI package:

    sudo apt-get install linode-cli
    

Manual Installation for Linux (All Distros)

In this section, you will learn how to install the Linode CLI manually on any Linux system. Use a package manager, CPAN, cpanminus, or your preferred method to install the following Perl modules:

  • Crypt::SSLeay
  • JSON
  • LWP::UserAgent
  • Mozilla::CA
  • Try::Tiny
  • WebService::Linode
  1. Download the Linode CLI tarball:

    curl -Lo linode-cli.tar.gz https://github.com/linode/cli/archive/master.tar.gz
    
  2. Extract the files:

    tar xf linode-cli.tar.gz
    
  3. Install the CLI:

    cd cli-master && perl Makefile.PL && sudo make install
    

Setup

If you installed the Linode CLI in a standard location, it should already be added to your PATH variable. That way, you will be able to invoke the CLI with the linode command. Otherwise, you will need to manually add the linode-cli folder location to your PATH, or call the program directly with the command /path/to/linode-cli/linode.

To start with, most users will want to run the configuration utility:

  1. Start the configuration utility:

    linode configure
    

    Output:

    This will walk you through setting default values for common options.
    
  2. Fill in your information at the prompts. You can skip optional questions by pressing Return. Here's some example output with the answers filled in.

    $ linode configure
    This will walk you through setting default values for common options.
    
    Linode Manager user name
    >> user1
    
    Linode Manager password for user1
    >>
    
    Default distribution when deploying a new Linode or rebuilding an existing one. (Optional)
    Valid options are:
      1 - Arch Linux 2012.10
      2 - Arch Linux 2012.10 32bit
      3 - Arch Linux 2013.06
      4 - Arch Linux 2013.06 32bit
      5 - CentOS 5.6
      6 - CentOS 5.6 32bit
      7 - CentOS 6.2
      8 - CentOS 6.4
      9 - Debian 7
     10 - Debian 7 32bit
     11 - Debian 7.4
     12 - Fedora 19
     13 - Fedora 20
     14 - Gentoo 2013-11-26
     15 - Slackware 13.37
     16 - Slackware 13.37 32bit
     17 - Slackware 14.1
     18 - Ubuntu 10.04 LTS
     19 - Ubuntu 10.04 LTS 32bit
     20 - Ubuntu 12.04 LTS
     21 - Ubuntu 12.04 LTS 32bit
     22 - Ubuntu 12.10
     23 - Ubuntu 12.10 32bit
     24 - Ubuntu 13.04
     25 - Ubuntu 13.04 32bit
     26 - Ubuntu 13.10
     27 - openSUSE 12.3
     28 - openSUSE 13.1
    Choose[ 1-28 ] or Enter to skip>> 26
    
    Default datacenter when deploying a new Linode. (Optional)
    Valid options are:
      1 - atlanta
      2 - dallas
      3 - fremont
      4 - london
      5 - newark
      6 - tokyo
    Choose[ 1-6 ] or Enter to skip>> 5
    
    Default plan when deploying a new Linode. (Optional)
    Valid options are:
      1 - Linode 1024
      2 - Linode 2048
      3 - Linode 4096
      4 - Linode 8192
      5 - Linode 16384
      6 - Linode 24576
      7 - Linode 32768
      8 - Linode 40960
    Choose[ 1-8 ] or Enter to skip>> 2
    
    Path to an SSH public key to install when deploying a new Linode. (Optional)
    >>
    
    Config written to /Users/user1/.linodecli/config
    

Once the CLI has your Linode Manager username and password, it will generate and use a new API key automatically.

Note

If you have two-factor authentication enabled, you will receive a prompt for the code after entering your password:

Two-factor authentication code
>> 123456

Enter your code at the prompt, then continue with the configuration tool as described above. Once the Linode CLI has access to your API key, you will no longer have to enter the code.

You can run the linode configure command again if your settings change. New answers will overwrite the old ones in the /Users/user1/.linodecli/config file in your user's home directory.

Note

If you don't run the configuration tool, you can add these options manually in the .linodecli/config file.

API Key

The Linode CLI requires your API key to function. If you need to generate an API key manually, read the API Key article. There are three ways to provide the key to the CLI. The configuration tool generates a new key and adds it to the .linodecli/config file automatically.

  • In the .linodecli/config file:

    File excerpt:.linodecli/config

    ...
    api-key SampleKey123456
    ...
    
  • As an environment variable:

    LINODE_API_KEY=SampleKey123456
    
  • Passed directly in the command:

    linode --api-key SampleKey123456
    

If you add your API key in the .linodecli/config file, or if you set it as an environment variable, the Linode CLI will automatically have access to your account. If you don't save or set the API key beforehand, you will have to enter it in the command when you use the CLI. The --api-key option should come at the end of the command. For example, your command would look like:

linode options --api-key SampleKey123456

Multiple Users

The default Linode CLI user is stored in the .linodecli/config file.

To set up the API for additional Linode users, you can run the linode configure command again, supplying a different username. Configuration files for additional users are stored with the file name pattern .linodecli/config_user1, with user1 being replaced by the actual username.

To invoke the CLI with a particular username, use the -u user1 option, with user1 being your actual username, at the end of the command.

Using the CLI

Invoke the CLI by prefacing your commands with linode. Make sure the linode-cli folder has been appended to your PATH variable (see the previous Setup section). In general, commands are in the format:

linode [object] [action] [action-options...] [options...]

If no object is given, the linode object is assumed. Available objects:

linode
domain
nodebalancer
stackscript
account

To specify a particular Linode user, add the -u user1 option, with user1 being your actual username, at the end of the command. If no user is specified, the default user described in the .linodecli/config file will be used.

The Linode CLI has many options available. In the rest of this article, we'll go over some common examples relating to Linodes, domains, NodeBalancers, StackScripts, and account details. To see all of the available options, view the man pages:

man linode
man linode-linode
man linode-domain
man linode-nodebalancer
man linode-stackscript
man linode-account

Press q to exit the man pages. You can also view more examples and options on the project's README page on GitHub.

Note

If you do something via the CLI that costs money (creating a Linode, upgrading a Linode, enrolling in a new service, etc.), the CLI will attempt to charge the credit card on file for your account or use any account credit available.

Linodes

The Linode CLI allows you to spin up new Linodes, issue reboots, upgrade plan sizes, and more.

Listing Linodes:

linode list

Creating a new Linode:

linode create <linode-label> --location <data center> --plan <linodeXXXX> --payment-term <X> --distribution "<Distribution>" --group <group-label>

Restarting a Linode:

linode restart <linode-label>

Resizing a Linode:

linode resize <linode-label> <linodeXXXX>

Rebuilding a Linode (rebuilding with a StackScript is available):

linode rebuild <linode-label> --distribution "<Distribution>" --password "<password>"

For your convenience, several of the options are explained below. For details on all the Linode options, please check the appropriate man page:

man linode-linode

--plan options

To view available Linode plan sizes for the --plan option, use the following command:

linode plans

Choose from the options below:

  • Linode 1024
  • Linode 2048
  • Linode 4096
  • Linode 8192
  • Linode 16384
  • Linode 24576
  • Linode 32768
  • Linode 40960

--location options

To view available data centers for new Linodes for the --location option, use either of the following commands:

linode locations
linode datacenters

Choose from the options below:

  • atlanta
  • dallas
  • fremont
  • london
  • newark
  • tokyo

--distribution options

To view available distributions for new Linodes for the --distribution option, use either of the following commands:

linode distros
linode distributions

Choose from the options below:

  • Arch Linux 2012.10
  • Arch Linux 2012.10 32bit
  • Arch Linux 2013.06
  • Arch Linux 2013.06 32bit
  • CentOS 5.6
  • CentOS 5.6 32bit
  • CentOS 6.2
  • CentOS 6.4
  • Debian 7
  • Debian 7 32bit
  • Debian 7.4
  • Fedora 19
  • Fedora 20
  • Gentoo 2013-11-26
  • Slackware 13.37
  • Slackware 13.37 32bit
  • Slackware 14.1
  • Ubuntu 10.04 LTS
  • Ubuntu 10.04 LTS 32bit
  • Ubuntu 12.04 LTS
  • Ubuntu 12.04 LTS 32bit
  • Ubuntu 12.10
  • Ubuntu 12.10 32bit
  • Ubuntu 13.04
  • Ubuntu 13.04 32bit
  • Ubuntu 13.10
  • openSUSE 12.3
  • openSUSE 13.1

Domains

With the Linode CLI, you can add and remove domains, update DNS records, and more.

Listing domains:

linode domain list

Listing domain records:

linode domain record-list <example.com>

Creating a domain record:

linode domain record-create <example.com> <RECORD TYPE> <subdomain> <X.X.X.X>

Updating a domain record:

linode domain record-update <example.com> <RECORD TYPE> <subdomain> [--priority <priority>]

To see all the available options, check the man pages:

man linode-domain

NodeBalancers

The Linode CLI allows you to manage your NodeBalancers from the command line.

Listing NodeBalancers:

linode nodebalancer list

Creating a NodeBalancer:

linode nodebalancer create <nodebalancer-label> <data center>

Configuring a NodeBalancer to handle traffic on a specific port:

linode nodebalancer config-create <nodebalancer-label> <port>

Configuring a node on a NodeBalancer:

linode nodebalancer node-create <nodebalancer-label> <port> <linode-label> <private-ip>:<port>

To see all the available options, check the man pages:

man linode-nodebalancer

StackScripts

The Linode CLI allows you to create and show StackScripts, and more.

Creating a StackScript:

linode stackscript create --label "<stackscript-label>" --codefile "</path/myscript.sh>" --distribution "<Distribution>"

Showing a StackScript:

linode stackscript show <stackscript-label>

StackScripts can be used to create or rebuild a Linode. Creating and rebuilding Linodes is covered in the Linodes section.

To see all the available options, check the man pages:

man linode-stackscript

Account

The CLI allows you to view your account billing details at a glance. Run the following command:

linode account show

Sample output:

          managed: yes
          balance: $ 0.00
    transfer pool: 6732.00GB
    transfer used: 13.02GB
transfer billable: 0.00GB
   billing method: prepay

To see all the available options, check the man pages:

man linode-account

Updating the CLI

Follow these instructions to update your Linode CLI package.

Mac OS X

Run the following Homebrew commands:

brew update
brew upgrade linode-cli

Debian and Ubuntu

Run the following commands:

sudo apt-get update
sudo apt-get upgrade linode-cli

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Sharon Campbell on Wednesday, March 19th, 2014 (r4339).