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

Maximize business outcomes on IBM Cloud with Concierge Platinum Services

2 min read - In the rapidly evolving digital landscape, we see that businesses are increasingly migrating to cloud services to enhance their operations, boost productivity and foster innovation. However, the process of transitioning clients to the cloud can often be intricate and time-intensive. To tackle this challenge head-on, IBM® offers clients access to a specialized Concierge Platinum Team, which is equipped with top-tier skills and expertise, to help expedite the cloud onboarding process and provide a smooth transition to Day Two Operations. What…

Bigger isn’t always better: How hybrid AI pattern enables smaller language models

5 min read - As large language models (LLMs) have entered the common vernacular, people have discovered how to use apps that access them. Modern AI tools can generate, create, summarize, translate, classify and even converse. Tools in the generative AI domain allow us to generate responses to prompts after learning from existing artifacts. One area that has not seen much innovation is at the far edge and on constrained devices. We see some versions of AI apps running locally on mobile devices with…

IBM Tech Now: April 8, 2024

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 96 On this episode, we're covering the following topics: IBM Cloud Logs A collaboration with IBM watsonx.ai and Anaconda IBM offerings in the G2 Spring Reports Stay plugged in You can check out the…

IBM Newsletters

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