Getting started with the Yandex Cloud command line interface (CLI)
The Yandex Cloud command line interface (CLI) is downloadable software you can use to manage your cloud resources via the command line.
The CLI is supported for the following operation systems and architectures:
- Linux: AMD64, x86, and ARM64.
- macOS: AMD64 and ARM64.
- Windows: AMD64 and x86.
The CLI is convenient for automating processes, including in bash scripts or CI/CD pipelines. You can also use the CLI to manage Yandex Cloud resources from environments without a graphical interface, such as from inside a Yandex Compute Cloud VM.
Most Yandex Cloud services are supported in the CLI. For the availability of interfaces for each service, see Overview of service interfaces.
Note
In some services, such as Yandex Message Queue, Yandex Cloud Postbox, and Yandex Cloud Notification Service, an HTTP API compatible with the Amazon API is implemented to support various third-party tools and SDKs. These services are not supported in the Yandex Cloud CLI. To work with them, use third-party tools, such as the AWS CLI
Yandex Object Storage supports operation both through the Yandex Cloud CLI and through the AWS CLI.
Install the CLI on the PC you want to use to manage your Yandex Cloud resources. Do it by running the commands shown below in the PC terminal.
Installation
Warning
The below command will automatically download and immediately execute the installation script. To preview the script's contents, download it manually and run it after a check.
This section provides a guide for interactive CLI installation using a script that:
- Identifies your OS and architecture.
- Downloads the executable with the latest stable CLI version for your environment.
- Performs a health check.
- Adds the CLI to the
PATHenvironment variable. - Generates autocompletion settings.
To manually set up the CLI installation directory, autocompletion, shell startup script, and add the CLI to the PATH environment variable, use the non-interactive CLI installation script.
Tip
You can manually download the executable archive and install the CLI.
For example, this may be useful if the target device does not have access to https://storage.yandexcloud.net. Download the archive containing the CLI executable on a different device, then transfer the archive to the target device using a method approved by your organization.
-
Run this command:
curl -sSL https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bashThe script will install the CLI and add the executable file path to the
PATHenvironment variable.Features
-
The script will update the
PATHvariable only if you run it in thebashorzshcommand shell.If you run the script in a different shell, add the CLI path to the
PATHvariable yourself. -
For autocompletion to work correctly when using
zsh, you need the shell version 5.1 or higher. If usingbashon CentOS and derivative distributions, install thebash-completionpackage.
-
-
After installation is complete, restart your terminal.
-
Run this command:
curl -sSL https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bashThe script will install the CLI and add the executable file path to the
PATHenvironment variable.This command runs the installation script using
bash. The script detects the user's command shell via theSHELLvariable and adds the configurations forzshto~/.zshrc. -
Restart your terminal for the changes to take effect.
For Windows, you can install the CLI using PowerShell or cmd.exe. In both cases, the installation script runs in PowerShell.
Warning
If PowerShell denies running scripts, check the active execution policies using the Get-ExecutionPolicy -List command. Only modify policies if this is allowed by your organization's security protocol. If the policy is enforced by the administrator or running scripts is prohibited, install the CLI without a script.
For more information about PowerShell execution policies, see the relevant Microsoft guides
-
Installation using PowerShell:
-
Run this command:
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://storage.yandexcloud.net/yandexcloud-yc/install.ps1') -
The installation script will ask whether to add the path to
ycto the PATH variable:Add yc installation dir to your PATH? [Y/n] -
Enter
Y. After this, you can use the Yandex Cloud CLI without restarting the command shell.
-
-
Installation from
cmd.exe:-
Run this command:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -Command "Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://storage.yandexcloud.net/yandexcloud-yc/install.ps1'))" && SET "PATH=%PATH%;%USERPROFILE%\yandex-cloud\bin" -
When prompted by the installation script, confirm whether to add the
ycpath to the PATH variable:Add yc installation dir to your PATH? [Y/n] -
Enter
Y. -
Restart your terminal for the changes to take effect.
-
For more information, see Working with the Yandex Cloud CLI and API in Microsoft Windows.
Enabling autocompletion
The CLI supports command autocompletion for the bash, zsh, and PowerShell command shells. To enable autocompletion:
In bash, autocompletion works immediately after installation. On CentOS and derivative distributions, first install the bash-completion package.
To enable autocompletion in zsh:
-
Open
~/.zshrcand add the following lines to the beginning of the file:autoload -Uz compinit compinitThe
ycinstallation script adds CLI initialization and autocompletion lines to the end of~/.zshrc. Place theautoloadandcompinitcalls above these lines; otherwise, you will get thecommand not found: compdeferror when you start the terminal.The final
~/.zshrcshould look as follows:autoload -Uz compinit compinit # The lines below were added automatically by the yc installation script. if [ -f "$HOME/yandex-cloud/path.bash.inc" ]; then source "$HOME/yandex-cloud/path.bash.inc"; fi if [ -f "$HOME/yandex-cloud/completion.zsh.inc" ]; then source "$HOME/yandex-cloud/completion.zsh.inc"; fi -
Restart the command shell or run the
exec -l $SHELLcommand. -
Check that autocompletion works: type
ycand press Tab twice. A list of available commands should appear.
Note
Below are instructions for setting up autocompletion in the zsh command shell, which is the default shell on macOS.
If you are using bash or macOS 10.14 Mojave or earlier, where bash is installed by default, edit the ~/.bash_profile file.
To enable autocompletion:
-
Open
~/.zshrcand add the following lines to the beginning of the file:autoload -Uz compinit compinitThe
ycinstallation script adds CLI initialization and autocompletion lines to the end of~/.zshrc. Place theautoloadandcompinitcalls above these lines; otherwise, you will get thecommand not found: compdeferror when you start the terminal.The final
~/.zshrcshould look as follows:autoload -Uz compinit compinit # The lines below were added automatically by the yc installation script. if [ -f "$HOME/yandex-cloud/path.bash.inc" ]; then source "$HOME/yandex-cloud/path.bash.inc"; fi if [ -f "$HOME/yandex-cloud/completion.zsh.inc" ]; then source "$HOME/yandex-cloud/completion.zsh.inc"; fiInstalling extended autocompletions
The
zsh-completionspackage extends the system's basic autocompletions. It is not required for theycautocompletion.To install the package:
-
Install Homebrew
. -
Install the
zsh-completionspackage:brew install zsh-completionsTip
If using
bash, install thebash-completionpackage instead ofzsh-completions. -
Add a section with
FPATHbefore theautoloadandcompinitlines. The final~/.zshrcshould look as follows:if type brew &>/dev/null; then FPATH=$(brew --prefix)/share/zsh-completions:$FPATH fi autoload -Uz compinit compinit # The lines below were added automatically by the yc installation script. if [ -f "$HOME/yandex-cloud/path.bash.inc" ]; then source "$HOME/yandex-cloud/path.bash.inc"; fi if [ -f "$HOME/yandex-cloud/completion.zsh.inc" ]; then source "$HOME/yandex-cloud/completion.zsh.inc"; fi
-
-
Restart the command shell or run the
exec -l $SHELLcommand. -
Check that autocompletion works: type
ycand press Tab twice. A list of available commands should appear.
Warning
Autocompletion is only supported in PowerShell 7 and above. Check the version using the $PSVersionTable.PSVersion command. If the version is lower than 7, install the latest version:
winget install Microsoft.PowerShell
Or download the installer manually from the PowerShell releases page
To enable autocompletion in PowerShell:
-
If you do not have a PowerShell profile, create one and open it in a text editor:
New-Item -Path $PROFILE -Type File -Force notepad $PROFILEInstead of
notepad, you can use any editor you prefer. For example, for VS Code, use thecode $PROFILEcommand. -
Add the following code to the file and save it:
Register-ArgumentCompleter -Native -CommandName yc -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $elements = $commandAst.CommandElements $allTokens = $elements | Select-Object -Skip 1 | ForEach-Object { $_.ToString() } $allTokens = $allTokens | Where-Object { $_ -match '^[\x20-\x7E]+$' } if ($wordToComplete -ne '') { $completedTokens = $allTokens | Select-Object -SkipLast 1 $queryTokens = @($completedTokens) + @("") } else { $queryTokens = @($allTokens) + @("") } $result = yc __completeNoDesc @queryTokens 2>$null $completions = $result | Where-Object { $_ -notmatch '^\:' -and $_ -notmatch '^Completion' } | Where-Object { $_.StartsWith($wordToComplete) } if ($completions.Count -eq 0 -and $wordToComplete -ne '') { $queryTokensFallback = @($completedTokens) + @($wordToComplete) $resultFallback = yc __completeNoDesc @queryTokensFallback 2>$null $completions = $resultFallback | Where-Object { $_ -notmatch '^\:' -and $_ -notmatch '^Completion' } | Where-Object { $_.StartsWith($wordToComplete) } } $completions | ForEach-Object { $parts = $_ -split '\t' [System.Management.Automation.CompletionResult]::new( $parts[0], $parts[0], 'ParameterValue', $parts[0] ) } }Note
By default, pressing Tab in PowerShell suggests the options one by one. To open a menu with all options and tooltips instead, add the following lines to the top of the file:
Set-PSReadLineOption -ShowToolTips Set-PSReadLineKeyHandler -Key Tab -Function MenuCompleteThese lines change the Tab behavior in all PowerShell commands, not just
yc. -
Restart PowerShell. Check that autocompletion works: type
ycand press Tab. A list of available commands should appear.
If you get an error during CLI installation, refer to CLI installation issues.
Creating a profile
Warning
To get authenticated in the CLI with a Yandex account, federated account, or local user account, you need a browser and a GUI.
If using the CLI on a server without a GUI, the recommended option is to authenticate with a service account.
If you cannot use a service account, authenticate via an SSH tunnel or X11 forwarding.
Tip
If your organization uses a proxy server to access Yandex Cloud, configure the CLI connection to the proxy server before running the yc init command.
To get authenticated using a Yandex account:
-
Get your email address:
- Navigate to your Yandex
account. - Copy your email address from the Contacts section.
- Navigate to your Yandex
-
Launch the profile creation wizard:
yc init --username=<email_address>If you run
yc initwithout stating--username, a Yandex account selection page will open in the browser for authentication. If you specify--usernamebeforehand, you will be taken to the sign-in page with the email address already filled in. -
Select the profile you want to set up authentication for or create a new one.
Welcome! This command will take you through the configuration process. Pick desired action: [1] Re-initialize this profile 'default' with new settings [2] Create a new profile -
The CLI prompts you to continue authentication in the browser. Press Enter to continue.
You are going to be authenticated via username '<email_address>'. Authentication web site will be opened. After your successful authentication, you will be redirected to 'https://console.yandex.cloud'. Press 'enter' to continue...On successful authentication, an IAM token will be saved in the profile. This IAM token will be used to authenticate each operation until the end of the token's lifetime (not more than 12 hours). After that, the CLI will once again prompt you to authenticate in the browser.
To extend the period during which you do not have to authenticate in the browser, use refresh tokens, which allow you to reissue IAM tokens without entering the browser. Do it by enabling refresh tokens at the organization level and initializing DPoP protection in the CLI.
-
Go back to the command line interface to finish creating the profile.
-
Select one of the clouds from the list of those you have access to:
Please select cloud to use: [1] cloud1 (id = aoe2bmdcvata********) [2] cloud2 (id = dcvatao4faoe********) Please enter your numeric choice: 2If there is only one cloud available, it will be selected automatically.
-
Select the default folder:
Please choose a folder to use: [1] folder1 (id = cvatao4faoe2********) [2] folder2 (id = tao4faoe2cva********) [3] Create a new folder Please enter your numeric choice: 1 -
To select the default availability zone for Compute Cloud, type
Y. To skip the setup, typen.Do you want to configure a default Yandex Compute Cloud availability zone? [Y/n] YIf you typed
Y, select the availability zone:Which zone do you want to use as a profile default? [1] ru-central1-a [2] ru-central1-b [3] ru-central1-d [4] Do not set default zone Please enter your numeric choice: 2 -
View your CLI profile settings:
yc config listResult:
subject-id: b1g159pa15cd******** username: <email_address> folder-id: b1g8o9jbt58******** compute-default-zone: ru-central1-b
To authenticate using a SAML-compatible identity federation:
-
Get your federation ID from your administrator.
-
Launch the profile creation wizard:
yc init --federation-id=<federation_ID>Note
If the server has no GUI or browser, you will get the following error:
ERROR: fill default credentials: federation id authentication is not supported on this system because the browser can not be openedAuthenticate using a service account. Alternatively, you can use an SSH tunnel or X11 forwarding.
-
Select the profile you want to set up authentication for or create a new one.
Welcome! This command will take you through the configuration process. Pick desired action: [1] Re-initialize this profile 'default' with new settings [2] Create a new profile -
The CLI prompts you to continue authentication in the browser. Press Enter to continue.
You are going to be authenticated via federation-id 'aje1f0hsgds3a********'. Your federation authentication web site will be opened. After your successful authentication, you will be redirected to 'https://console.yandex.cloud'. Press 'enter' to continue...On successful authentication, an IAM token will be saved in the profile. This IAM token will be used to authenticate each operation until the end of the token's lifetime (not more than 12 hours). After that, the CLI will once again prompt you to authenticate in the browser.
To extend the period during which you do not have to authenticate in the browser, use refresh tokens, which allow you to reissue IAM tokens without entering the browser. Do it by enabling refresh tokens at the organization level and initializing DPoP protection in the CLI.
-
Go back to the command line interface to finish creating the profile.
-
Select one of the clouds from the list of those you have access to:
Please select cloud to use: [1] cloud1 (id = aoe2bmdcvata********) [2] cloud2 (id = dcvatao4faoe********) Please enter your numeric choice: 2If there is only one cloud available, it will be selected automatically.
-
Select the default folder:
Please choose a folder to use: [1] folder1 (id = cvatao4faoe2********) [2] folder2 (id = tao4faoe2cva********) [3] Create a new folder Please enter your numeric choice: 1 -
To select the default availability zone for Compute Cloud, type
Y. To skip the setup, typen.Do you want to configure a default Yandex Compute Cloud availability zone? [Y/n] YIf you typed
Y, select the availability zone:Which zone do you want to use as a profile default? [1] ru-central1-a [2] ru-central1-b [3] ru-central1-d [4] Do not set default zone Please enter your numeric choice: 2 -
View your CLI profile settings:
yc config listResult:
federation-id: aje1f0hs6oja******** subject-id: ajea53egl28l******** cloud-id: b1g159pa15cd******** folder-id: b1g8o9jbt58******** compute-default-zone: ru-central1-b
To authenticate using a local user account:
-
Launch the profile creation wizard:
User poolEmail-
Get your user pool ID from your administrator.
-
Launch the profile creation wizard:
yc init --userpool-id=<user_pool_ID>
-
Get your email address:
- Go to the My account
portal. - In the left-hand panel, select
Profile. - Copy the email address from the Contacts section.
- Go to the My account
-
Launch the profile creation wizard:
yc init --username=<email_address>
-
-
Select the profile you want to set up authentication for or create a new one.
Welcome! This command will take you through the configuration process. Pick desired action: [1] Re-initialize this profile 'default' with new settings [2] Create a new profile -
The CLI prompts you to continue authentication in the browser. Press Enter to continue.
You are going to be authenticated via userpool-id 'ek0auknfc0mh********'. Your userpool authentication web site will be opened. After your successful authentication, you will be redirected to cloud console. Press 'enter' to continue...On successful authentication, an IAM token will be saved in the profile. This IAM token will be used to authenticate each operation until the end of the token's lifetime (not more than 12 hours). After that, the CLI will once again prompt you to authenticate in the browser.
To extend the period during which you do not have to authenticate in the browser, use refresh tokens, which allow you to reissue IAM tokens without entering the browser. Do it by enabling refresh tokens at the organization level and initializing DPoP protection in the CLI.
-
Go back to the command line interface to finish creating the profile.
-
Select one of the clouds from the list of those you have access to:
Please select cloud to use: [1] cloud1 (id = aoe2bmdcvata********) [2] cloud2 (id = dcvatao4faoe********) Please enter your numeric choice: 2If there is only one cloud available, it will be selected automatically.
-
Select the default folder:
Please choose a folder to use: [1] folder1 (id = cvatao4faoe2********) [2] folder2 (id = tao4faoe2cva********) [3] Create a new folder Please enter your numeric choice: 1 -
To select the default availability zone for Compute Cloud, type
Y. To skip the setup, typen.Do you want to configure a default Yandex Compute Cloud availability zone? [Y/n] YIf you typed
Y, select the availability zone:Which zone do you want to use as a profile default? [1] ru-central1-a [2] ru-central1-b [3] ru-central1-d [4] Do not set default zone Please enter your numeric choice: 2 -
View your CLI profile settings:
yc config listResult:
User poolEmailuserpool-id: ek0auknfc0mh******** subject-id: ek00cd1m8hdd8******** cloud-id: b1g159pa15cd******** folder-id: b1g8o9jbt58******** compute-default-zone: ru-central1-bsubject-id: b1g159pa15cd******** username: <email_address> folder-id: b1g8o9jbt58******** compute-default-zone: ru-central1-b
Examples of commands
See below for how to create a cloud network, a subnet, and a VM connected to that subnet.
-
View the description of the CLI commands for working with cloud networks:
yc vpc network --help -
Create a cloud network in the folder specified in your CLI profile:
yc vpc network create \ --name my-yc-network \ --labels my-label=my-value \ --description "my first network via yc" -
In the
my-yc-networkcloud network, create a subnet:yc vpc subnet create \ --name my-yc-subnet-a \ --zone ru-central1-a \ --range 10.1.2.0/24 \ --network-name my-yc-network \ --description "my first subnet via yc" -
Get a list of all cloud networks in the directory specified in your CLI profile:
yc vpc network listResult:
+----------------------+------------------+-------------------------+ | ID | NAME | DESCRIPTION | +----------------------+------------------+-------------------------+ | skesdqhkc644******** | my-ui-network | my first network via ui | | c6449hbqqar1******** | my-yc-network | my first network via yc | +----------------------+------------------+-------------------------+Get the same list with more details in YAML format:
yc vpc network list --format yamlResult:
- id: skesdqhkc644******** folder_id: ijkl9012 created_at: "2018-09-05T09:51:16Z" name: my-ui-network description: "my first network via ui" labels: {} - id: c6449hbqqar1******** folder_id: ijkl9012 created_at: "2018-09-05T09:55:36Z" name: my-yc-network description: "my first network via yc" labels: my-label: my-value -
Create a VM and connect it to
my-yc-subnet-a:-
Create a key pair (public and private keys) for SSH access to the VM.
-
Create a Linux VM:
yc compute instance create \ --name my-yc-instance \ --network-interface subnet-name=my-yc-subnet-a,nat-ip-version=ipv4 \ --zone ru-central1-a \ --ssh-key ~/.ssh/id_ed25519.pubWhere
ssh-keyis the path to a public key for SSH access. The VM will automatically create theyc-useruser with the specified public key.
-
-
Connect to the VM over SSH:
-
Learn the public IP address of the VM. To do this, view detailed information about your VM:
yc compute instance get my-yc-instanceIn the command output, find the address of the VM in the
one_to_one_natsection:one_to_one_nat: address: 130.193.32.90 ip_version: IPV4 -
Connect to the VM over SSH as
yc-userusing the private key and the VM's public IP address you got earlier:ssh yc-user@130.193.32.90
-
-
Delete the
my-yc-instanceVM,my-yc-subnet-asubnet, andmy-yc-networknetwork:yc compute instance delete my-yc-instance yc vpc subnet delete my-yc-subnet-a yc vpc network delete my-yc-network