简体   繁体   中英

Permission denied lost connection

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?

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 azureuser@ip.xxx.xxx.xxx:/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

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 user@10.10.10.10:/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 user@10.10.10.10:/home/user/file.txt /home/user/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM