I was created Azure Ubuntu server 16.04 VM and Installed LAMP, now I would like to upload my project files to Azure VM, How can I do it?, I have SSH public key text with me. Can I archive this through ssh?

enabled inbound rules for HTTP, https, and ssh.

Step 1:

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar


Permission denied (publickey)

Step 2:

scp -i ~/.ssh/id_rsa.pub /var/www/html azureuser@sample.region.cloudapp.azure.com:phpinfo.php /var/www/html


cp: omitting directory '/var/www/html'
Warning: Identity file /home/azureuser/.ssh/id_rsa.pub not accessible: No such file or directory.
Permission denied (publickey)

Step 3:

ssh-copy-id -i ~/.ssh/id_rsa.pub azureuser@sample.region.cloudapp.azure.com`

note : it appends the key in VM's `/home/.ssh/authorized_keys


cp: omitting directory '/var/www/html'
Enter passphrase for key '/home/azureuser/.ssh/authorized_keys':
Permission denied (publickey)

Step 4: tried again with -r option

azureuser@myVM:~$ scp -r /var/www/html azureuser@sample.region.cloudapp.azure.com:phpinfo.php /var/www/html


cp: cannot copy a directory, '/var/www/html', into itself, '/var/www/html/html'
Permission denied (publickey).
  • Use -i option for scp command and provide full path to your private SSH key to this -i option – Alex Jul 31 '18 at 5:00
  • @Alex - it gives error, updated my question. – 151291 Jul 31 '18 at 5:39
  • @151291 , add "-r " option in your command and copy a directory and its contents. – Nancy Xiong Jul 31 '18 at 9:26
  • @Alex - cp: cannot copy a directory, '/var/www/html', into itself, '/var/www/html/html' Permission denied (publickey). – 151291 Jul 31 '18 at 9:30
  • 1
    @151291 The keys should come in pairs. The private key usually is saved as ~/.ssh/id_rsa file. – Nancy Xiong Aug 1 '18 at 9:16

Assuming you yourself are in a *nix environment, are you able to ssh to the server with public key auth?

user@mypc:> ssh azureuser@sample.region.cloudapp.azure.com

Assuming thats successful, make sure your user has permissions to write in that folder, if not you can add your user to the webserver user group: usermod -aG www-data azureuser replacing "www-data" with whatever group owns the folder /var/www/html

Once permissions are sorted something like the following should work:

user@mypc:> scp -r ./folder azureuser@sample.region.cloudapp.azure.com:/var/www/html


user@mypc:> scp ./index.html azureuser@sample.region.cloudapp.azure.com:/var/www/html/
  • Might be worth trying something like this as a test first: user@mypc:> scp ./testfile.txt azureuser@sample.region.cloudapp.azure.com:~/ This would eliminate public key auth from being the issue. – Bennett Aug 2 '18 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.