August 31, 2023 By Henrik Loeser 4 min read

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.

Introduction

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.

Conclusion

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 (@data_henrik@mastodon.social) or LinkedIn.

Was this article helpful?
YesNo

More from Cloud

Enhance your data security posture with a no-code approach to application-level encryption

4 min read - Data is the lifeblood of every organization. As your organization’s data footprint expands across the clouds and between your own business lines to drive value, it is essential to secure data at all stages of the cloud adoption and throughout the data lifecycle. While there are different mechanisms available to encrypt data throughout its lifecycle (in transit, at rest and in use), application-level encryption (ALE) provides an additional layer of protection by encrypting data at its source. ALE can enhance…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters