skip to Main Content

I have created a simple VM in azure in which I will have to host a very simple server written in C.

To send the folder hosted on my computer containing the server to the virtual machine, I use the command from powershell:

scp -r <path_to_key.pem> <path_to_folder_on_my_pc> <azureuser@ip:/home/azureuser/>

The result of this command is

azureuser@ip: Permission denied (publickey).
lost connection

Would anyone who has had this problem have a solution ?

2

Answers


  1. This problem may cause in your public key. please Ensure that the public key is also present in your home directory when you create the Azure Virtual machine with a public key. Meaning The public key was kept on your both local computer and virtual machine Then, with the permission accept from your local workstation, you can use ssh into your Azure Virtual Machine using the public key.

    Reference: linux – Can’t scp to Azure’s VM – by ale93p

    Suppose if you want to use the private key in the SCP then you will have to use the below command to copy files from the local system to the Azure VM

    sudo scp -i ~/.ssh/id_rsa /path/cert.pem [email protected]:/home/file/user/local
    

    Make sure that the Azure VM’s incoming NSG rule has port 22 opened and by default VM’S page is reachable through port 80/443 over public IP address.

    For more information in detail, please refer this link:

    Use SSH keys to connect to Linux VMs – Azure Virtual Machines | Microsoft Docs

    Use SCP to move files to and from a VM – Azure Virtual Machines | Microsoft Docs

    Login or Signup to reply.
  2. You need to copy your private key to the ~/.ssh/ directory on the host from which you want to transfer the file. Once you have done that, you can use the following command:

    scp -i ~/.ssh/<name of your key>.pem <path of file to transfer> user@azureip:<target directory>
    

    So for example you want to transfer file.txt to your Azure VM (IP of 10.10.10.10) with the private key named key.pem

    scp -i ~/.ssh/key.pem file.txt [email protected]:/home/user/
    

    To pull a file from your Azure VM to your local host, you reverse the order of the file to get and user@azureip.

    scp -i ~/.ssh/key.pem [email protected]:/home/user/file.txt /home/user/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search