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.

Categories

More from Cloud

IBM Cloud VMware as a Service introduces multitenant as a new, cost-efficient consumption model

4 min read - Businesses often struggle with ongoing operational needs like monitoring, patching and maintenance of their VMware infrastructure or the added concerns over capacity management. At the same time, cost efficiency and control are very important. Not all workloads have identical needs and different business applications have variable requirements. For example, production applications and regulated workloads may require strong isolation, but development/testing, training environments, disaster recovery sites or other applications may have lower availability requirements or they can be ephemeral in nature,…

IBM accelerates enterprise AI for clients with new capabilities on IBM Z

5 min read - Today, we are excited to unveil a new suite of AI offerings for IBM Z that are designed to help clients improve business outcomes by speeding the implementation of enterprise AI on IBM Z across a wide variety of use cases and industries. We are bringing artificial intelligence (AI) to emerging use cases that our clients (like Swiss insurance provider La Mobilière) have begun exploring, such as enhancing the accuracy of insurance policy recommendations, increasing the accuracy and timeliness of…

IBM NS1 Connect: How IBM is delivering network connectivity with premium DNS offerings

4 min read - For most enterprises, how their users access applications and data is an essential part of doing business, and how they service those application and data responses has a direct correlation to revenue generation.    According to We Are Social’s Digital 2023 Global Overview Report, there are 5.19 billion people around the world using the internet in 2023. There’s an imperative need for businesses to trust their networks to deliver meaningful content to address customer needs.  So how responsive is the…

Kubernetes version 1.28 now available in IBM Cloud Kubernetes Service

2 min read - We are excited to announce the availability of Kubernetes version 1.28 for your clusters that are running in IBM Cloud Kubernetes Service. This is our 23rd release of Kubernetes. With our Kubernetes service, you can easily upgrade your clusters without the need for deep Kubernetes knowledge. When you deploy new clusters, the default Kubernetes version remains 1.27 (soon to be 1.28); you can also choose to immediately deploy version 1.28. Learn more about deploying clusters here. Kubernetes version 1.28 In…