Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Command line interface
  • Getting started with the CLI
  • Step-by-step instructions
    • All instructions
    • CLI installation
    • Authentication
      • Authenticating as a user
      • Authenticating as a service account
      • Authenticating as a federated user
    • Profile management
      • Creating a profile
      • Managing profile parameters
      • Getting profile information
      • Activating a profile
      • Deleting a profile
  • Concepts
    • Running commands
    • CLI configuration
    • Synchronous and asynchronous command execution modes
  • CLI releases
  • Troubleshooting
  • CLI reference
    • Overview
    • CLI manage
      • init
      • version
      • help
      • config
        • Overview
        • profile
          • Overview
          • activate
          • delete
          • create
          • list
          • get
        • unset
        • set
        • get
        • list
      • components
        • Overview
        • restore
        • update
    • Operations manage
      • Overview
      • wait
      • get
    • Service manage
      • load-balancer
        • Overview
        • network-load-balancer
          • Overview
          • list-operations
          • remove-listener
          • add-listener
          • target-states
          • detach-target-group
          • attach-target-group
          • stop
          • start
          • delete
          • update
          • create
          • list
          • get
        • target-group
          • Overview
          • list-operations
          • remove-targets
          • add-targets
          • delete
          • update
          • create
          • list
          • get
      • managed-kafka
        • Overview
        • cluster
          • Overview
          • reschedule-maintenance
          • move
          • update
          • create
          • stop
          • start
          • list-logs
          • list-hosts
          • list-operations
          • delete
          • list
          • get
        • topic
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • user
          • Overview
          • delete
          • update
          • create
          • list
          • get
      • managed-elasticsearch
        • Overview
        • cluster
          • Overview
          • reschedule-maintenance
          • remove-labels
          • add-labels
          • update-config
          • update
          • stop
          • start
          • list-operations
          • list-logs
          • list-backups
          • backup
          • delete
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • delete
          • add
          • list
        • backup
          • Overview
          • list
          • get
        • extension
          • Overview
          • update
          • delete
          • create
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
      • managed-redis
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • move
          • list-operations
          • list-logs
          • list-backups
          • backup
          • rebalance
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • reschedule-maintenance
          • start-failover
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • delete
          • add
          • list
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
        • shards
          • Overview
          • delete
          • add
          • list
          • get
      • managed-postgresql
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • move
          • list-operations
          • list-logs
          • list-backups
          • backup
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • reschedule-maintenance
          • start-failover
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • update-config
          • delete
          • update
          • add
          • list
        • database
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • user
          • Overview
          • revoke-permission
          • grant-permission
          • delete
          • update
          • create
          • list
          • get
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
      • managed-sqlserver
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • list-operations
          • list-backups
          • backup
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • start-failover
          • restore
          • create
          • list
          • get
        • host
          • Overview
          • update
          • list
        • database
          • Overview
          • delete
          • backup-import
          • backup-export
          • restore
          • create
          • list
          • get
        • user
          • Overview
          • revoke-permission
          • grant-permission
          • delete
          • update
          • create
          • list
          • get
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
      • managed-mysql
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • move
          • list-operations
          • list-logs
          • list-backups
          • backup
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • reschedule-maintenance
          • start-failover
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • delete
          • update
          • add
          • list
        • database
          • Overview
          • delete
          • create
          • list
          • get
        • user
          • Overview
          • revoke-permission
          • grant-permission
          • delete
          • update
          • create
          • list
          • get
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
      • managed-mongodb
        • Overview
        • cluster
          • Overview
          • enable-sharding
          • stop
          • start
          • move
          • list-operations
          • list-logs
          • list-backups
          • backup
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • reschedule-maintenance
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • stepdown
          • restart
          • resetup
          • delete
          • add
          • list
        • database
          • Overview
          • delete
          • create
          • list
          • get
        • user
          • Overview
          • revoke-permission
          • grant-permission
          • delete
          • update
          • create
          • list
          • get
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
        • shards
          • Overview
          • delete
          • add
          • list
          • get
      • managed-clickhouse
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • move
          • remove-graphite-rollup
          • add-graphite-rollup
          • remove-external-dictionary
          • add-external-dictionary
          • set-compression
          • clear-compression
          • list-operations
          • list-logs
          • list-backups
          • backup
          • add-zookeeper
          • delete
          • remove-labels
          • add-labels
          • update-config
          • update
          • reschedule-maintenance
          • restore
          • create
          • list
          • get
        • hosts
          • Overview
          • delete
          • update
          • add
          • list
        • shards
          • Overview
          • delete
          • update-config
          • update
          • add
          • list
          • get
        • shard-groups
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • database
          • Overview
          • delete
          • create
          • list
          • get
        • user
          • Overview
          • remove-quota
          • update-quota
          • add-quota
          • revoke-permission
          • grant-permission
          • delete
          • update
          • create
          • list
          • get
        • backup
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
        • ml-model
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • format-schema
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • version
          • Overview
          • list
      • certificate-manager
        • Overview
        • certificate
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • delete
          • update
          • request
          • create
          • list
          • content
          • get
      • cdn
        • Overview
        • resource
          • Overview
          • delete
          • get-provider-cname
          • update
          • create
          • list
          • get
        • origin
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • origin-group
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • provider
          • Overview
          • activate
          • list-activated
        • cache
          • Overview
          • prefetch
          • purge
      • kms
        • Overview
        • symmetric-key
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • rotate
          • cancel-version-destruction
          • schedule-version-destruction
          • set-primary-version
          • delete
          • update
          • create
          • list-versions
          • list
          • get
        • symmetric-crypto
          • Overview
          • re-encrypt
          • generate-data-key
          • decrypt
          • encrypt
      • ydb
        • Overview
        • database
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • remove-labels
          • add-labels
          • delete
          • start
          • stop
          • update
          • restore
          • backup
          • create
          • list
          • get
        • storage-type
          • Overview
          • list
          • get
        • resource-preset
          • Overview
          • list
          • get
        • backup
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • delete
          • list
          • get
      • dns
        • Overview
        • zone
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • remove-labels
          • add-labels
          • replace-records
          • delete-records
          • add-records
          • list-records
          • delete
          • update
          • create
          • list
          • get
        • bind-file
          • Overview
          • migrate-to-terraform
      • vpc
        • Overview
        • network
          • Overview
          • move
          • list-operations
          • list-route-tables
          • list-security-groups
          • list-subnets
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • route-table
          • Overview
          • move
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • security-group
          • Overview
          • update-rule-meta
          • update-rules
          • move
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • subnet
          • Overview
          • move
          • list-used-addresses
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • remove-range
          • add-range
          • update
          • create
          • list
          • get
        • address
          • Overview
          • move
          • list-operations
          • delete
          • update
          • create
          • list
          • get
      • resource-manager
        • Overview
        • cloud
          • Overview
          • list-operations
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • update
          • list
          • get
        • folder
          • Overview
          • list-operations
          • set-access-bindings
          • add-access-binding
          • remove-access-binding
          • delete
          • list-access-bindings
          • remove-labels
          • create
          • add-labels
          • update
          • list
          • get
      • lockbox
        • Overview
        • secret
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • cancel-version-destruction
          • schedule-version-destruction
          • deactivate
          • activate
          • delete
          • add-version
          • update
          • create
          • list-versions
          • list
          • get
        • payload
          • Overview
          • get
      • application-load-balancer
        • Overview
        • load-balancer
          • Overview
          • target-states
          • remove-location
          • add-location
          • enable-traffic
          • disable-traffic
          • list-operations
          • update-stream-sni
          • update-sni
          • add-stream-sni
          • add-sni
          • remove-sni
          • remove-listener
          • update-stream-listener
          • update-listener
          • add-stream-listener
          • add-listener
          • delete
          • stop
          • start
          • update
          • create
          • list
          • get
        • virtual-host
          • Overview
          • update-grpc-route
          • insert-grpc-route
          • remove-grpc-route
          • prepend-grpc-route
          • append-grpc-route
          • update-http-route
          • insert-http-route
          • remove-http-route
          • prepend-http-route
          • append-http-route
          • delete
          • update
          • create
          • list
          • get
        • target-group
          • Overview
          • remove-targets
          • add-targets
          • delete
          • update
          • create
          • list
          • get
        • backend-group
          • Overview
          • delete-stream-backend
          • update-stream-backend
          • add-stream-backend
          • delete-grpc-backend
          • update-grpc-backend
          • add-grpc-backend
          • delete-http-backend
          • update-http-backend
          • add-http-backend
          • delete
          • update
          • create
          • list
          • get
        • http-router
          • Overview
          • delete
          • update
          • create
          • list
          • get
      • dataproc
        • Overview
        • resource-preset
          • Overview
          • list
          • get
        • cluster
          • Overview
          • list-operations
          • list-ui-links
          • list-hosts
          • stop
          • start
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • subcluster
          • Overview
          • delete
          • update
          • create
          • list
          • get
        • job
          • Overview
          • create-hive
          • create-mapreduce
          • create-pyspark
          • create-spark
          • log
          • list
          • get
          • cancel
      • cloud-desktop
        • Overview
        • desktop
          • Overview
          • reset-password
          • delete
          • list
          • list-operations
          • get-rdp-file
          • create
          • get
        • group
          • Overview
          • list-operations
          • create
          • list-desktops
          • list
          • get
          • remove-access-bindings
          • add-access-bindings
          • list-access-bindings
          • set-access-bindings
          • delete
      • managed-greenplum
        • Overview
        • cluster
          • Overview
          • stop
          • start
          • list-operations
          • list-logs
          • delete
          • create
          • remove-labels
          • add-labels
          • list
          • get
        • resource-preset
          • Overview
          • get
            • Overview
            • segment
            • master
          • list
            • Overview
            • segment
            • master
        • hosts
          • Overview
          • list
            • Overview
            • master
            • segment
      • compute
        • Overview
        • instance
          • Overview
          • list-operations
          • move
          • remove-one-to-one-nat
          • add-one-to-one-nat
          • update-network-interface
          • detach-filesystem
          • attach-filesystem
          • detach-disk
          • attach-new-disk
          • attach-disk
          • restart
          • start
          • stop
          • get-serial-port-output
          • delete
          • remove-labels
          • add-labels
          • remove-metadata
          • add-metadata
          • update-container
          • update
          • create-with-container
          • create
          • list
          • get
        • disk
          • Overview
          • list-operations
          • move
          • delete
          • resize
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • disk-type
          • Overview
          • list
          • get
        • image
          • Overview
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • get-latest-from-family
          • list
          • get
        • snapshot
          • Overview
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • zone
          • Overview
          • list
          • get
        • instance-group
          • Overview
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-logs
          • list-operations
          • delete-instances
          • stop-instances
          • list-instances
          • delete
          • remove-labels
          • add-labels
          • remove-metadata
          • add-metadata
          • start
          • stop
          • update
          • create
          • list
          • get
        • placement-group
          • Overview
          • list-operations
          • list-instances
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • host-type
          • Overview
          • list
          • get
        • host-group
          • Overview
          • list-operations
          • list-instances
          • list-hosts
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • disk-placement-group
          • Overview
          • list-operations
          • list-disks
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • filesystem
          • Overview
          • remove-labels
          • add-labels
          • resize
          • update
          • delete
          • create
          • list-operations
          • list
          • get
        • connect-to-serial-port
      • managed-kubernetes
        • Overview
        • cluster
          • Overview
          • list-nodes
          • list-operations
          • list-node-groups
          • start
          • stop
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
          • get-credentials
        • node-group
          • Overview
          • list-nodes
          • list-operations
          • delete
          • remove-node-labels
          • add-node-labels
          • remove-labels
          • add-labels
          • remove-metadata
          • add-metadata
          • update
          • create
          • list
          • get
        • list-versions
        • create-token
      • iam
        • Overview
        • role
          • Overview
          • list
          • get
        • service-account
          • Overview
          • list-operations
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • delete
          • update
          • create
          • list
          • get
        • certificate
          • Overview
          • list-operations
          • delete
          • update
          • create
          • list
          • get
        • key
          • Overview
          • delete
          • create
          • list
          • get
        • federation
          • Overview
          • list-operations
          • list-user-accounts
          • add-user-accounts
          • delete
          • update
          • create
          • list
          • get
        • api-key
          • Overview
          • delete
          • create
          • list
          • get
        • user-account
          • Overview
          • get
        • access-key
          • Overview
          • delete
          • create
          • list
          • get
        • create-token
      • logging
        • Overview
        • group
          • Overview
          • list-operations
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-resources
          • stats
          • delete
          • update
          • create
          • list
          • get
        • write
        • read
      • serverless
        • Overview
        • api-gateway
          • Overview
          • remove-domain
          • add-domain
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • delete
          • update
          • create
          • get-spec
          • list
          • get
        • function
          • Overview
          • version
            • Overview
            • logs
            • get-by-tag
            • remove-tag
            • set-tag
            • create
            • get
            • list
          • runtime
            • Overview
            • list
          • remove-scaling-policy
          • set-scaling-policy
          • list-scaling-policies
          • deny-unauthenticated-invoke
          • allow-unauthenticated-invoke
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • invoke
          • logs
          • list-operations
          • tag-history
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • trigger
          • Overview
          • create
            • Overview
            • yds
            • billing-budget
            • logging
            • cloud-logs
            • container-registry
            • object-storage
            • internet-of-things
            • message-queue
            • timer
          • list-operations
          • resume
          • pause
          • delete
          • remove-labels
          • add-labels
          • update
          • list
          • get
        • container
          • Overview
          • revision
            • Overview
            • deploy
            • get
            • list
          • deny-unauthenticated-invoke
          • allow-unauthenticated-invoke
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • rollback
          • update
          • create
          • list
          • get
        • mdbproxy
          • Overview
          • update
            • Overview
            • clickhouse
            • postgresql
          • create
            • Overview
            • clickhouse
            • postgresql
          • list-operations
          • delete
          • remove-labels
          • add-labels
          • list
          • get
      • datatransfer
        • Overview
        • transfer
          • Overview
          • deactivate
          • activate
          • list
          • get
          • delete
          • update
          • create
        • endpoint
          • Overview
          • create
            • Overview
            • clickhouse-target
            • clickhouse-source
            • mongo-target
            • mongo-source
            • mysql-target
            • mysql-source
            • postgres-target
            • postgres-source
          • update
            • Overview
            • clickhouse-target
            • clickhouse-source
            • mongo-target
            • mongo-source
            • mysql-target
            • mysql-source
            • postgres-target
            • postgres-source
          • list
          • delete
          • get
      • container
        • Overview
        • registry
          • Overview
          • configure-docker
          • remove-ip-permissions
          • add-ip-permissions
          • set-ip-permissions
          • list-ip-permissions
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
        • image
          • Overview
          • list-vulnerabilities
          • list-scan-results
          • get-last-scan-result
          • get-scan-result
          • scan
          • delete
          • list
          • get
        • cluster
          • Overview
          • list-nodes
          • list-operations
          • list-node-groups
          • start
          • stop
          • delete
          • remove-labels
          • add-labels
          • update
          • create
          • list
          • get
          • get-credentials
        • node-group
          • Overview
          • list-nodes
          • list-operations
          • delete
          • remove-node-labels
          • add-node-labels
          • remove-labels
          • add-labels
          • remove-metadata
          • add-metadata
          • update
          • create
          • list
          • get
        • repository
          • Overview
          • lifecycle-policy
            • Overview
            • list-dry-run-results
            • dry-run
            • delete
            • update
            • create
            • list
            • get
            • list-dry-run-affected-images
            • get-dry-run-result
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • list
          • get
      • iot
        • Overview
        • mqtt
          • Overview
          • subscribe
          • publish
        • device
          • Overview
          • certificate
            • Overview
            • delete
            • add
            • list
          • password
            • Overview
            • delete
            • add
            • list
          • delete
          • remove-topic-aliases
          • add-topic-aliases
          • logs
          • update
          • create
          • list
          • get
        • registry
          • Overview
          • certificate
            • Overview
            • delete
            • add
            • list
          • password
            • Overview
            • delete
            • add
            • list
          • list
          • get
          • list-device-topic-aliases
          • delete
          • remove-labels
          • add-labels
          • logs
          • update
          • create
      • organization-manager
        • Overview
        • user
          • Overview
          • remove
          • list
        • organization
          • Overview
          • leave
          • list-operations
          • remove-access-binding
          • add-access-binding
          • set-access-bindings
          • list-access-bindings
          • update
          • list
          • get
        • federation
          • Overview
          • saml
            • Overview
            • certificate
              • Overview
              • list
              • create
              • get
              • update
              • delete
              • list-operations
            • get
            • list
            • create
            • list-operations
            • list-user-accounts
            • add-user-accounts
            • update
            • delete
  1. Getting started with the CLI

Getting started with the command-line interface

Written by
Yandex Cloud
,
improved by
Pushkin
  • Installation
  • Creating a profile
  • Examples of commands

The Yandex Cloud command-line interface (CLI) provides downloadable software for managing your cloud resources from the command line.

Installation

Linux
macOS
Windows
  1. Run the command:

    curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash
    

    The script will install the CLI and add the executable file path to the environment variable PATH.

    Note

    The script will update PATH only if you run it in the bash or zsh command shell.

    If you run the script in a different shell, add the path to the CLI to the variable PATH yourself.

  2. After installation is complete, restart your terminal.

  1. Run the command:

    curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash
    

    The script will install the CLI and add the executable file path to the environment variable PATH.

  2. Restart your terminal for the changes to take effect.

The CLI supports command completion for the bash shell. For command completion to work:

  1. Install the Homebrew package manager.

  2. Install the bash-completion package:

    brew install bash-completion
    

    The installation script will update the ~/.bash_profile file:

    # The next line updates PATH for Yandex Cloud CLI.
    if [ -f '/Users/<username>/yandex-cloud/path.bash.inc' ]; then source '/Users/<username>/yandex-cloud/path.bash.inc'; fi
    # The next line enables shell command completion for yc.
    if [ -f '/Users/<username>/yandex-cloud/completion.bash.inc' ]; then source '/Users/<username>/yandex-cloud/completion.bash.inc'; fi
    
  3. After the installation is complete, add the following lines to the ~/.bash_profile file. Insert them above the lines automatically added by the installation script.

    if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
    fi
    
  4. Restart your terminal.

For Windows, the CLI can be installed using PowerShell and cmd:

  • To install using PowerShell:

    1. Run the command:

      iex (New-Object System.Net.WebClient).DownloadString('https://storage.yandexcloud.net/yandexcloud-yc/install.ps1')
      
    2. The installation script will ask whether to add the path to yc to the PATH variable:

      Add yc installation dir to your PATH? [Y/n]
      
    3. Enter Y. After this, you can use the Yandex Cloud CLI without restarting the command shell.

  • To install using cmd:

    1. Run the command:

      @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://storage.yandexcloud.net/yandexcloud-yc/install.ps1'))" && SET "PATH=%PATH%;%USERPROFILE%\yandex-cloud\bin"
      
    2. The installation script will ask whether to add the path to yc to the PATH variable:

      Add yc installation dir to your PATH? [Y/n]
      
    3. Enter Y.

    4. Restart your terminal for the changes to take effect.

Creating a profile

If you aren't connected to the management console yet, log in to the console and accept the user agreement by clicking Log in.

As a user
As a service account
As a federated user

To authenticate as a user:

  1. Get an OAuth token from Yandex.OAuth. To do this, follow the link and click Allow.

  2. To configure your CLI profile, run the command yc init.

  3. Enter your OAuth token when prompted by the command.

    Please go to https://oauth.yandex.com/authorize?response_type=token&client_id=1a6990aa636648e9b2ef855fa7bec2fb
     in order to obtain OAuth token.
    
    Please enter OAuth token: AaAaBbBbCcCcDdDdEeEeFfFfGgGg
    
  4. At the command prompt, select one of the clouds from the list of those you have access to:

    Please select cloud to use:
     [1] cloud1 (id = aoe2bmdcvatao4frg22b)
     [2] cloud2 (id = dcvatao4faoe2bmrg22b)
    Please enter your numeric choice: 2
    

    If only one cloud is available, it's selected automatically.

  5. Select the default folder:

    Please choose a folder to use:
     [1] folder1 (id = cvatao4faoe2bmdrg22b)
     [2] folder2 (id = tao4faoe2cvabmdrg22b)
     [3] Create a new folder
    Please enter your numeric choice: 1
    
    1. Select the default availability zone for Yandex Compute Cloud:
    Do you want to configure a default Yandex Compute Cloud availability zone? [Y/n] Y
    Which zone do you want to use as a profile default?
     [1] ru-central1-a
     [2] ru-central1-b
     [3] ru-central1-c
     [4] Don't set default zone
    Please enter your numeric choice: 2
    
  6. View your CLI profile settings:

    yc config list
    

Before you start, get your service account ready:

  1. Authenticate in the CLI as a user.
  2. If you don't have a service account yet, create one and configure access rights for it.

To authenticate as a service account:

  1. Get a list of service accounts that exist in your cloud:

    yc iam service-account --folder-id <folder ID> list
    +----------------------+------------+
    |          ID          |    NAME    |
    +----------------------+------------+
    | aje3932acd0c5ur7dagp | default-sa |
    +----------------------+------------+
    
  2. Create an authorized key for the service account and save it to the key.json file:

    yc iam key create --service-account-name default-sa --output key.json
    id: aje83v701b1un777sh40
    service_account_id: aje3932acd0c5ur7dagp
    created_at: "2019-08-26T12:31:25Z"
    key_algorithm: RSA_2048
    
  3. Add the service account authorized key to the CLI profile.

    1. Create a new CLI profile:

      yc config profile create sa-profile
      
    2. Add an authorized key:

      yc config set service-account-key key.json
      
  4. Make sure that the service account parameters are added correctly:

    yc config list
    service-account-key:
      id: aje83v701b1un777sh40
      service_account_id: aje3932acd0c5ur7dagp
      created_at: "2019-08-26T12:31:25Z"
      key_algorithm: RSA_2048
      public_key: |
        -----BEGIN PUBLIC KEY-----
        MIIBIjANBg...
        -----END PUBLIC KEY-----
      private_key: |
        -----BEGIN PRIVATE KEY-----
        MIIEvwIBAD...
        -----END PRIVATE KEY-----
    
  5. Configure your profile to run commands.

    Some commands require that you specify unique IDs for your cloud and folder. You can specify their details in the profile or use a specific flag for these commands.

    1. Specify the cloud in your profile:

      yc config set cloud-id <cloud ID>
      

      Or run commands with the --cloud-id parameter.

    2. Specify a folder in the profile:

      yc config set folder-id <folder ID>
      

      Or use the --folder-id parameter in your commands.

    All operations in this profile will be performed on behalf of the linked service account. You can change the profile parameters or switch to another profile.

To authenticate using an SAML-compatible identity federation:

  1. Get your federation ID from your administrator.

  2. Launch the profile creation wizard:

    yc init --federation-id=<federation ID>
    
  3. 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
    
  4. The CLI prompts you to continue authentication in the browser. Press Enter to continue.

    You are going to be authenticated via federation-id 'aje1f0hsgds3aas2f6ai2'.
    Your federation authentication web site will be opened.
    After your successful authentication, you will be redirected to 'https://console.cloud.yandex.com'.
    
    Press 'enter' to continue...
    

    On successful authentication, the IAM token is saved in the profile. This token is used to authenticate each operation until the token expires. After that, the CLI again displays a prompt to authenticate in the browser.

  5. Go back to the command-line interface to finish creating the profile.

  6. Select the default folder:

    Please choose a folder to use:
     [1] folder1 (id = cvatao4faoe2bmdrg22b)
     [2] folder2 (id = tao4faoe2cvabmdrg22b)
     [3] Create a new folder
    Please enter your numeric choice: 1
    
  7. Select the default availability zone for Yandex Compute Cloud:

    Do you want to configure a default Yandex Compute Cloud availability zone? [Y/n] Y
    Which zone do you want to use as a profile default?
     [1] ru-central1-a
     [2] ru-central1-b
     [3] ru-central1-c
     [4] Don't set default zone
    Please enter your numeric choice: 2
    
  8. View your CLI profile settings:

    yc config list
    federation-id: aje1f0hs6ojais2f6ai2
    ...
    

Examples of commands

The following steps describe how to create a cloud network, subnet, and virtual machine that is connected to this subnet.

  1. View the description of the CLI commands for working with cloud networks:
    yc vpc network --help
    
  2. 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"
    
  3. Create a subnet in the cloud network my-yc-network:
    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"
    
  4. Get a list of all cloud networks in the directory specified in your CLI profile:
    yc vpc network list
    
    +----------------------+------------------+-------------------------+
    |          ID          |       NAME       |       DESCRIPTION       |
    +----------------------+------------------+-------------------------+
    | skesdqhkc6449hbqqar1 | my-ui-network    | my first network via ui |
    | c6449hbqqar1skesdqhk | my-yc-network    | my first network via yc |
    +----------------------+------------------+-------------------------+
    
    Get the same list with more details in YAML format:
    yc vpc network list --format yaml
    
    - id: skesdqhkc6449hbqqar1
      folder_id: ijkl9012
      created_at: "2018-09-05T09:51:16Z"
      name: my-ui-network
      description: "my first network via ui"
      labels: {}
    - id: c6449hbqqar1skesdqhk
      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
    
  5. Create a VM and connect it to the subnet my-yc-subnet-a:
    1. Prepare the key pair (public and private keys) for SSH access to the VM.
    2. Create a Linux VM instance:
      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_rsa.pub
      
      Pass the path to the public key for SSH access in the ssh-key parameter. A user named yc-user will be automatically created in the VM's OS with the specified public key.
  6. Connect to the virtual machine over SSH:
    1. Find out the public IP address of the virtual machine. To do this, view detailed information about your virtual machine:
      yc compute instance get my-yc-instance
      
      In the command output, find the address of the VM in the one_to_one_nat section:
      one_to_one_nat:
          address: 130.193.32.90
          ip_version: IPV4
      
    2. Connect to the virtual machine over SSH on behalf of the yc-user user, using the private key:
      ssh yc-user@130.193.32.90
      
  7. Delete the my-yc-instance VM, the my-yc-subnet-a subnet, and the my-yc-network network:
    yc compute instance delete my-yc-instance
    yc vpc subnet delete my-yc-subnet-a
    yc vpc network delete my-yc-network
    

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Installation
  • Creating a profile
  • Examples of commands