Blockchain News

Getting started with the IBM Cloud command line interface

When working in a computer shell, the IBM Cloud command line interface (CLI) is the way to manage the lifecycle of your resources. Many of the services offered by IBM Cloud provide additional CLI functionality. You can even access IBM Cloud on private endpoints for increased security and have the login process integrate with single sign-on procedures.

In this blog post, we give you an introduction to the IBM Cloud CLI tool and share useful tips and tricks to get you started on the command line. This can be on your computer or by utilizing the IBM Cloud Shell (as shown in Figure 1 below):

Figure 1: IBM Cloud Shell with CLI command to list available plug-ins.


The IBM Cloud command line interface (CLI) tool is a utility you can use to manage your resources. It is extensible through plug-ins, with a long list of plug-ins for cloud services available. The tool allows you to create new service instances, assign and revoke privileges, and administrate resources (including deleting them and managing their retention).

After the initial installation of the CLI tool on your computer, it offers a set of core commands. They include general commands for login, setting the target (account, region, resource group) and some configuration. The core features consist of account and user management, commands to work with resources and resource groups, and everything interfacing with Identity and Access Management (IAM).

To extend the CLI functionality, there are commands to manage plug-ins. As shown in the screenshot above, the command ibmcloud plugin repo-plugins lists available plug-ins. Many of the IBM Cloud services offer a CLI plug-in with service-specific commands. One such plug-in is for IBM Cloud Code Engine. You can find instructions on how to install a service-related plug-in and documentation for each command as part of the service documentation and in the CLI documentation:

Figure 2: IBM Cloud CLI documentation for plug-ins.

Command line completion

To simplify and speed up work on the command line, we recommend you enable shell autocompletion for IBM Cloud CLI. This feature of the computer shell is sometimes called command line completion or tab completion. You can expand a partially typed command by pressing the tab key. Thus, it helps to quickly compose the CLI command and it can give an overview of available command (options) without needing the help function.

When composing a command, be aware of how to use quotation marks for quoted strings or JSON objects.

CLI sessions

With all the setup done, it is time to actually utilize the command line tool. To work with your resources, you need to log in to IBM Cloud. There are different options available, and they depend on your type of user ID. If you are not sure about your user ID, start by running a simple ibmcloud login command and follow the instructions for entering your email address as user name and a password. Because many IBM Cloud users are corporate users (with federated IDs), you might find that you need to use single sign-on (SSO), including some multi-factor authentication (MFA).

An alternative to passwords is to provide an API key. With their help, you can log in the associated user or service ID. Other forms of authentication include using a compute resource token (see my blog post on turning your container into a trusted cloud identity) or a passcode. To obtain the passcode, you must be already logged in to the IBM Cloud console. Then, click on your profile in the upper right and on Log in to CLI and API (see Figure 3 below):

Figure 3: IBM Cloud console: Where to obtain a passcode for login.

It brings up a window with an ibmcloud login command, as shown in the next screenshot. As you may notice, the command has a user (-u) with the name passcode and a special, only-valid-for-five-minutes passcode as password (-p). Copy the command and use it in your CLI environment to log in.

Once logged in, try to list your resources (ibmcloud resource service-instances) or to retrieve the OAuth tokens for the session (ibmcloud iam oauth-tokens). You can use that token for working with IBM Cloud API functions, but that is an entirely different topic.

Figure 4: IBM Cloud console: Obtain information for CLI login with passcode.

In this blog post, we introduced you to the IBM Cloud CLI tool (command line interface). It allows you to access and manage your resources from a computer terminal. The CLI tool has a modular architecture and offers plug-ins for many of the IBM Cloud services. The support for autocompletion/command line completion simplifies tasks.

To learn more about the CLI tool and how to use it in an efficient way, we recommend these resources:

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik), Mastodon ( or LinkedIn.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Translate »