Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
All solutions
    • All solutions for Compute Cloud
    • You are unable to add a Committed Volume of Services (CVoS) for Compute Cloud
    • You see a "Permission denied" error when connecting to a VM created in Terraform
    • No nested virtualization support
    • UEFI support and data import from GPT-formatted disks
    • Fixing the "Not enough resources" error on launching a virtual machine
    • Recovering access to a VM with a lost SSH key
    • Fixing issues with creating disk snapshots
    • Boot disk size failed to increase
    • VM instance shuts down on the "instance guest stop processing" operation
    • Fixing the "WARNING REMOTE HOST IDENTIFICATION HAS CHANGED" error
    • Fixing a non-replicable disk breakdown
    • Fixing connection issues with Kosmos VM
    • Fixing password reset issues for VMs based on a Kosmos image
    • Options to migrate a VM image to Yandex Cloud
    • Changing the boot disk for an instance to SSD
    • Getting details about RAM consumption for Compute Cloud instances
    • Creating VMs having multiple network interfaces
    • Decreasing VM disk size
    • Exporting disk images of Compute Cloud VM instances
    • Transferring VMs between folders or clouds
    • Setting up GUI and graphic environment on Linux VMs
    • Using an ISO image for deploying VM instances
    • Monitoring incoming or outgoing VM traffic
    • How to use WinSCP to connect to a Linux VM in Yandex Cloud with a key generated at VM creation
    • How to back up a VM with rollback support
    • How to connect via SSH as root with a password or key
    • How to track memory usage
    • How to save snapshots and images locally
    • How to change an internal IP address
    • How to read the "Connections quota utilization" chart
    • What is the disk access speed for a VM
    • How to create a VM with password access
    • What is the maximum number of network interfaces that can be connected to a VM

In this article:

  • Issue description
  • Solution
  1. Compute Cloud
  2. You see a "Permission denied" error when connecting to a VM created in Terraform

You see a «Permission denied» error when connecting to a VM created in Terraform

Written by
Yandex Cloud
Updated at September 19, 2023
  • Issue description
  • Solution

Issue descriptionIssue description

You see a "Permission denied" error when trying to establish an SSH connection to a VM created in Terraform.

SolutionSolution

If you pass a key in the ssh-keys option, the text specified in the SSH key's comment will not be processed.
As a result, the key will be assigned to the user set as default in the cloud-init configuration for this image.

Note

Such a username might vary between VM images. For more information, see the documentation article.

If you need to add a user with a specific name when creating your VM, pass the metadata file in a cloud-init-compatible YAML format, adding the metadata file path to the Terraform's manifest:

  1. Create a UTF-8 encoded text file with the following contents:

    #cloud-config
    users:
      - name: <user name>
        groups: sudo
        shell: /bin/bash
        sudo: 'ALL=(ALL) NOPASSWD:ALL'
        ssh_authorized_keys:
          - ssh-ed25519 AAAAB3Nza......OjbSMRX user@example.com
          - ssh-ed25519 AAAAB3Nza......Pu00jRN user@desktop
    
  2. Add the following text to the metadata section in your Terraform manifest:

    metadata = {
        user-data = "${file("<file_path>")}"
    }
    

You can look up details about the user and the key in the serial port output for the created VM. If the SSH key is valid, the output should include:

ci-info: ++++++++++++++++++++++++++++++++++++++Authorized keys from /home/test/.ssh/authorized_keys for user ubuntu++++++++++++++++++++++++++++++++++++
ci-info: +---------+-------------------------------------------------------------------------------------------------+---------+----------------------+
ci-info: | Keytype |                                       Fingerprint (sha256)                                      | Options |       Comment        |
ci-info: +---------+-------------------------------------------------------------------------------------------------+---------+----------------------+
ci-info: | ssh-rsa | 7f:fa:ab:5c:b5:67:6b:4a:65:1e:65:bb:93:13:0b:0b:d2:06:52:63:bf:ed:c6:16:4d:55:b6:fb:c5:a2:30:f0 |    -    | some_text            |
ci-info: +---------+-------------------------------------------------------------------------------------------------+---------+----------------------+

Where ubuntu is the username, and ssh-rsa is the SSH key fingerprint.

Alert

The serial output containing this data is available after the VM is created and until it restarts for the first time.

Was the article helpful?

Previous
You are unable to add a Committed Volume of Services (CVoS) for Compute Cloud
Next
No nested virtualization support
Yandex project
© 2025 Yandex.Cloud LLC