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

Helping enterprises across regulated industries leverage hybrid cloud and AI

3 min read - At IBM Cloud, we are committed to helping enterprises across industries leverage hybrid cloud and AI technologies to help them drive innovation. For true transformation to begin, we believe it is key to understand the unique challenges organizations are facing—whether it is keeping data secured, addressing data sovereignty requirements or speeding time to market to satisfy consumers. For those in even the most highly regulated industries, we have seen these challenges continue to grow as they navigate changing regulations. We…

Migration Acceleration Program for IBM Cloud

2 min read - The cloud has emerged as a transformative technology platform, offering flexibility, scalability and cost-effectiveness. Enterprise cloud migration strategies seek to be business-driven with an integrated technology, operational and financial adoption plan. Knowing where you are, where you are going, and how you get there is critical to sustainable success. Building an end-to-end plan with confidence can be a daunting undertaking, and enterprise leaders find it challenging to design and execute a cloud migration plan. To address these challenges, we continue…

How Wasabi and IBM help clients deliver on data-driven innovation

2 min read - Last year, Wasabi Technologies and IBM Cloud® joined forces to drive data innovation across hybrid cloud environments, positioning enterprises to run applications across any environment—on premises, in the cloud or at the edge—and enabling users to cost efficiently access and use key business data and analytics in real time. As we head into the second half of 2024, IBM Cloud and Wasabi continue to build new ways to expand their relationship. This growing relationship has the potential to reshape how…

IBM Newsletters

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