An Overview of the Linode CLI
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The Linode CLI is a wrapper around the Linode API that allows you to manage your Linode account from the command line. Virtually any task that can be done through the Linode Manager can be done through the CLI, making it an excellent tool for scripting.
This guide describes the basics of installing and working with the CLI. It also offers examples illustrating how to complete common tasks using the CLI.
Install the CLI
The easiest way to install the CLI is through Pip:
Install the CLI:
pip3 install linode-cli --upgrade
If you haven’t yet installed python3
and pip3
, below is a brief outline separated by Distro and Operating System to help you complete the basic installation process:
Ubuntu/Debian
Ensure that all available packages are up to date:
sudo apt update
Install python3 and pip3:
sudo apt install python3 && sudo apt install python3-pip
Install the Linode CLI using pip3:
sudo pip3 install linode-cli
CentOS/RHEL Stream and Fedora
Ensure that all available packages are up to date:
dnf upgrade
Install python3 and pip3:
sudo dnf install python3 && sudo dnf install python3-pip
Install the Linode CLI using pip3:
sudo pip3 install linode-cli
CentOS 7
Ensure that all available packages are up to date:
sudo yum update
Install python3 and pip3:
sudo yum install python3 && sudo yum install python3-pip
Install the Linode CLI using pip3:
sudo pip3 install linode-cli
Windows 10
Download the latest stable Windows package for python3 for your system at Python’s Downloads Page.
Open up the installer
.exe
to begin the python installation process using Window’s GUI.Before proceeding, ensure that your version of Python is added to PATH by checking the box which enables this option:
Select the Customize Installation option to proceed.
Ensure that
pip
all desired optional features are selected before proceeding to the next step. Thepip
installation is required by the Linode CLI.In the next step, ensure that the Install for all users option is enabled. Your configuration should reflect the following:
Select
Next
to proceed with the installation. Once the installation is complete, a message will confirm Python3 was successfully installed will appear that can be safely closed.Open the windows command prompt and enter the following command to complete installation of the Linode CLI:
sudo pip3 install linode-cli
Mac OSx
By default, python3 should already be installed and configured on the latest versions of Mac OSx. If for whatever reason it is not, you can use brew
to install python3 which will additionally include pip
by default:
brew install python3
Initial Configuration of the Linode CLI
You need a Personal Access Token to use the CLI. Use the Linode Cloud Manager to obtain a token.
Run the
linode-cli configure --token
command, you will be prompted with the CLI’s configuration script. Paste your access token (which will then be used by default for all requests made through the CLI) at the prompt. You will be prompted to choose defaults for Linodes created through the CLI (region, type, and image). These are optional, and can be overridden for individual commands. Update these defaults at any time by runninglinode-cli configure
:Welcome to the Linode CLI. This will walk you through some initial setup. First, we need a Personal Access Token. To get one, please visit https://cloud.linode.com/profile/tokens and click "Create a Personal Access Token". The CLI needs access to everything on your account to work correctly. Personal Access Token:
NoteThe CLI installs a bash completion file. On OSX, you may have to source this file before it can be used. To do this, addsource /etc/bash_completion.d/linode-cli.sh
to your~/.bashrc
file.
Options
Help
View information about any part of the CLI, including available actions and required parameters, with the --help
flag:
linode-cli --help
linode-cli linodes --help
linode-cli linodes create --help
Customize Output Fields
By default, the CLI displays a set of pre-selected fields for each type of response. If you would like to see all available fields, use the --all
flag:
linode-cli linodes list --all
Specify exactly which fields you would like to receive with the -format
option:
linode-cli linodes list --format 'id,region,memory'
JSON Output
The CLI will return output in tabulated format for easy readability. If you prefer to work with JSON, use the --json
flag. Adding the --pretty
flag will format the JSON output to make it more readable:
linode-cli regions list --json --pretty
|
|
Machine Readable Output
You can also display the output as plain text. By default, tabs are used as a delimiter, but you can specify another character with the --delimiter
option:
linode-cli regions list --text
|
|
linode-cli regions list --text --delimiter ";"
|
|
Examples
This section reviews some common examples related to
Accounts and
Events,
Domains,
Linode Instances,
Linode Kubernetes Engine (LKE),
NodeBalancers,
Object Storage,
Block Storage Volumes, and
Support Tickets. Other actions are available. Use linode-cli linodes --help
for a complete list.
Account
View or update your account information, add payment methods, view notifications, make payments, create OAuth clients, and do other related tasks through the account
action:
View your account:
linode-cli account view
View your account settings:
linode-cli account settings
Make a payment:
linode-cli account payment-create --cvv 123 --usd 20.00
View notifications:
linode-cli account notifications-list
Events
View a list of events on your account:
linode-cli events list
View details about a specific event:
linode-cli events view $event_id
Mark an event as read:
linode-cli events mark-read $event_id
Domains
List the Domains on your account:
linode-cli domains list
View all domain records in a specific Domain:
linode-cli domains records-list $domain_id
Delete a Domain:
linode-cli domains delete $domain_id
Create a Domain:
linode-cli domains create --type master --domain www.example.com --soa_email email@example.com
Create a new A record in a Domain:
linode-cli domains records-create $domain_id --type A --name subdomain --target 192.0.2.0
Linode Instances
Tasks related to Linode instances are performed with linode-cli linodes [ACTION]
.
List all of the Linodes on your account:
linode-cli linodes list
Filter results to a particular region:
linode-cli linodes list --region us-east
Filtering works on many fields throughout the CLI. Use
--help
for each action to see which properties are filterable.Create a new Linode:
linode-cli linodes create --root_pass mypassword
The defaults you specified when configuring the CLI will be used for the new Linode’s type, region, and image. Override these options by specifying the values:
linode-cli linodes create --root_pass mypassword --region us-east --image linode/debian9 --group webservers
If you are not writing a script, it is more secure to use
--root_pass
without specifying a password. You will then be prompted to enter a password:linode-cli linodes create --root_pass
For commands targeting a specific Linode, you will need that Linode’s ID. The ID is returned when creating the Linode, and can be viewed by listing the Linodes on your account as described above. Store the ID of the new Linode (or an existing Linode) for later use:
export linode_id=<id-string>
View details about a particular Linode:
linode-cli linodes view $linode_id
Boot, shut down, or reboot a Linode:
linode-cli linodes boot $linode_id linode-cli linodes reboot $linode_id linode-cli linodes shutdown $linode_id
View a list of available IP addresses for a specific Linode:
linode-cli linodes ips-list $linode_id
Add a private IP address to a Linode:
linode-cli linodes ip-add $linode_id --type ipv4 --public false
Create a new disk for a Linode:
linode-cli linodes disk-create $linode_id --size 2700 --root_pass mypassword --filesystem raw --no-defaults
Note
Even if you set the--filesystem
toraw
, the defaults you specified when configuring the CLI will be used for setting a Linode’s disk image for this disk, overriding the filesystem setting. To create a disk without the default image, using only the parameters you send in this command, use the--no-defaults
flag.List all disks provisioned for a Linode:
linode-cli linodes disks-list $linode_id
Upgrade your Linode. If an upgrade is available for the specified Linode, it will be placed in the Migration Queue. It will then be automatically shut down, migrated, and returned to its last state:
linode-cli linodes upgrade $linode_id
Rebuild a Linode:
linode-cli linodes rebuild $linode_id --image linode/debian9 --root_pass
Rebuild a Linode, adding a populated authorized_keys file:
linode-cli linodes rebuild $linode_id --image linode/debian9 --root_pass --authorized_keys "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEC+DOVfw+8Jsw1IPrYCcU9/HCuKayCsV8bXjsHqX/Zq email@example.com"
If your key exists on your filesystem, you can also substitute its value in the CLI command with
cat
. For example:linode-cli linodes rebuild $linode_id --image linode/debian9 --root_pass --authorized_keys "$(cat ~/.ssh/id_rsa.pub)"
Many other actions are available. Use linode-cli linodes --help
for a complete list.
Linode Kubernetes Engine (LKE)
Lists current Kubernetes Clusters available on your account:
linode-cli lke clusters-list
Create a Kubernetes Cluster. The Kubernetes Cluster will be created asynchronously. You can use the events system to determine when the Kubernetes Cluster is ready to use:
linode-cli lke cluster-create \ --label cluster12345 \ --region us-central \ --k8s_version 1.16 \ --node_pools.type g6-standard-4 --node_pools.count 6 \ --node_pools.type g6-standard-8 --node_pools.count 3 \ --tags ecomm
Update Kubernetes Cluster:
linode-cli lke cluster-update $cluster_id \ --label lkecluster54321 \ --tags ecomm \ --tags blog \ --tags prod \ --tags monitoring
Delete a Cluster you have permission to
read_write
:linode-cli lke cluster-delete $cluster_id
List all active Node Pools on a Kubernetes Cluster:
linode-cli lke pools-list $cluster_id
Create a Node Pool on a Kubernetes Cluster:
linode-cli lke pool-create $cluster_id \ --type g6-standard-4 \ --count 6
Update Node Pool in a Kubernetes Cluster. When a Node Pool’s count is changed, the Nodes in that pool will be replaced in a rolling fashion.
linode-cli lke pool-update $cluster_id $pool_id \ --count 6
Delete a Node Pool from a Kubernetes Cluster:
linode-cli lke pool-delete $cluster_id $pool_id
View the Kubeconfig file for the Kubernetes Cluster:
linode-cli lke kubeconfig-view $cluster_id
Other actions are available. Use linode-cli lke --help
for a complete list.
NodeBalancers
Create a new NodeBalancer:
linode-cli nodebalancers create --region us-east --label new-balancer
Create a configuration for a NodeBalancer:
linode-cli nodebalancers config-create $nodebalancer_id
Attach a Node to a NodeBalancer:
linode-cli nodebalancers node-create --address 192.200.12.34:80 --label node-1
To delete a node, you will need the ID of the NodeBalancer, configuration, and node:
linode-cli nodebalancers node-delete $nodebalancer_id $config_id $node_id
Other actions are available. Use linode-cli nodebalancers --help
for a complete list.
Object Storage
List the current Object Storage Clusters available to use:
linode-cli object-storage clusters-list
Create a new Object Storage Key for your account:
linode-cli object-storage keys-create --label "my-object-storage-key"
List Object Storage Keys for authenticating to the Object Storage S3 API:
linode-cli object-storage keys-list
Update an Object Storage Key label:
linode-cli object-storage keys-update --keyId $key_id --label "my-new-object-storage-key"
Upload a TLS/SSL Certificate:
linode-cli object-storage ssl-upload us-east-1 example-bucket --certificate "my-full-certificate" --private_key "my-full-private-key"
View an Active TLS/SSL Certificate:
linode-cli object-storage ssl-view us-east-1 example-bucket
Revoke an Object Storage Key:
linode-cli object-storage keys-delete $key_id
Delete an Active TLS/SSL Certificate:
linode-cli object-storage ssl-delete us-east-1 example-bucket
Cancel Object Storage on your Account. All buckets on the Account must be empty before Object Storage can be cancelled.
linode-cli object-storage cancel
Block Storage Volumes
List your current Volumes:
linode-cli volumes list
Create a new Volume, with the size specified in GB:
linode-cli volumes create --label my-volume --size 100 --region us-east
Specify a
linode_id
to create the Volume and automatically attach it to a specific Linode:linode-cli volumes create --label my-volume --size 100 --linode_id $linode_id
Attach or detach the Volume from a Linode:
linode-cli volumes attach $volume_id --linode_id $linode_id linode-cli volumes detach $volume_id
Resize a Volume (size can only be increased):
linode-cli volumes resize $volume_id --size 200
Delete a Volume:
linode-cli volumes delete $volume_id
Support Tickets
List your Support Tickets:
linode-cli tickets list
Open a new Ticket:
linode-cli tickets create --description "Detailed description of the issue" --summary "Summary or quick title for the Ticket"
If your issue concerns a particular Linode, Volume, Domain, or NodeBalancer, pass the ID with
--domain_id
,--linode-id
,--volume_id
, etc.List replies for a Ticket:
linode-cli tickets replies $ticket_id
Reply to a Ticket:
linode-cli tickets reply $ticket_id --description "The content of your reply"
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.
This page was originally published on