How to upload local files to Azure Linux VM? - my machine to Azure VM

-1

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

Error:

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

Error:

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

Error:

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

Error:

cp: cannot copy a directory, '/var/www/html', into itself, '/var/www/html/html'
Permission denied (publickey).

151291

Posted 2018-07-31T04:39:09.110

Reputation: 99

Use -i option for scp command and provide full path to your private SSH key to this -i option – Alex – 2018-07-31T05:00:33.187

@Alex - it gives error, updated my question. – 151291 – 2018-07-31T05:39:22.977

@151291 , add "-r " option in your command and copy a directory and its contents. – Nancy Xiong – 2018-07-31T09:26:55.180

@Alex - cp: cannot copy a directory, '/var/www/html', into itself, '/var/www/html/html' Permission denied (publickey). – 151291 – 2018-07-31T09:30:20.597

@Alex - I think, need to change permission of -i ssh path. it may help. – 151291 – 2018-07-31T09:31:16.223

@151291 You can select a destination path which the azureuser has permissions to write like /home/azureuser/test. Also, make sure your current user has permissions in the source host. – Nancy Xiong – 2018-07-31T09:58:16.307

@NancyXiong-MSFT I am beginner to azure, may I get some more explain about it?, sample commands helps me more. – 151291 – 2018-07-31T10:01:52.093

When you using scp, you should use private key in option -i, not a public one. Public key should be on Azure side in file ~/.ssh/authorized_keys. Also, when you trying scp, make sure that private key's permissions is 600 (it must not be readable by anyone, but you) otherwise operation will be refused. Make also sure that keys you using has original line ending(line should be ended with \n only(0x0A), not a windows's \r\n 0x0D,0x0A). – Alex – 2018-07-31T13:49:50.820

@Alex - how can I find my private key path? – 151291 – 2018-08-01T07:42:46.027

1@151291 The keys should come in pairs. The private key usually is saved as ~/.ssh/id_rsa file. – Nancy Xiong – 2018-08-01T09:16:47.513

When you get access to Azure, you granted with 2 encryption files , one is public key, that should be on remote server and another one it is private key that used on a client side to be able to connect to remote server. The path where you saved private key is a path that you need to supply to the option -i of scp – Alex – 2018-08-01T12:22:48.923

@NancyXiong-MSFT , @alex - yes, used private key to -i , now tried with scp, the public key error gone but getting directory not found exception using -r also. scp /var/www/html/info.php azureuser@sample.region.cloudapp.azure.com:/var/www/html /var/www/html/info.php: No such file or directory. – 151291 – 2018-08-02T09:06:18.223

1Thanks to all, Its working, the last issue due to run in the azure cli, I must use my local machine terminal. – 151291 – 2018-08-02T09:32:57.330

Answers

0

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

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:

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

or

scp ./index.html azureuser@sample.region.cloudapp.azure.com:/var/www/html/

Bennett

Posted 2018-07-31T04:39:09.110

Reputation: 1

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 – 2018-08-02T02:30:50.690

0

Was having the same error today, I resolved it using this command (to not try to directly add it to a specific folder, and then move it):

scp -r myFile.jar username@hostname:~/.

Hope this will help someone...

Loup Ollivier

Posted 2018-07-31T04:39:09.110

Reputation: 1