Search code examples
scp

Scp file from local to remote server with user password


I'm trying to copy a file from my local machine macosx 10.11.6 to a remote server (digital ocean droplet) ubuntu 18.04 using scp. I tried

scp -r /path/to/local/file username@ipaddress:/path/to/folder/where/to/copy

and I got permission denied.

I ssh into the server cd /path/to/folder/where/to/copy and test with touch index.txt and got permission denied.

I tried to touch index.txt with sudo which worked after input the password.

I tried install and use sshpas

sshpass -p 'mypassword' scp -r /path/to/local/file username@ipaddress:/path/to/folder/where/to/copy

And I got permission denied again.

What is the correct way to copy that file from local to the remote server passing the user password?


Solution

  • As mentioned here SSH SCP Local file to Remote in Terminal Mac Os X , I had to do it in two times. scp -r /path/to/local/file username@ipAddress:/home/username then ssh username@ipAddress sudo mv file path/to/destination/folder