1

I'm trying to upload a file from my local desktop to a server and I'm using this command:

scp myFile.txt [email protected]:/opt/nicescada/web

following the structure: scp filename user@ip:/remotePath.

But I get "Permission Denied". I tried using sudo , but I get the same message. I'm being able to download from the server to my local machine, so I assume I have all permissions needed.

What can be wrong in that line of code?

2 Answers 2

3

In case your /desired/path on your destination machine has write access only for root, and if you have an account on your destination machine with sudo privileges (super user privileges by prefixing a sudo to your command), you could also do it the following way:

Option 1 based on scp:

  1. copy the file to a location on your destination machine where you have write access like /tmp:
    scp file user@destinationMachine:/tmp
    
  2. Login to your destination machine with:
    ssh user@destinationMachine
    
  3. Move the file to your /desired/path with:
    sudo mv /tmp/file /desired/path
    

In case you have a passwordless sudo setup you could also combine step 2. and 3. to

ssh user@destination sudo mv /tmp/file /desired/path

Option 2 based on rsync

Another maybe even simpler option would be to use rsync:

rsync -e "ssh -tt" --rsync-path="sudo rsync" file user@destinationMachine:/desired/path

with -e "ssh -tt" added to run sudo without having a tty.

2

Try and specify the full destination path:

scp myFile.txt [email protected]:/opt/nicescada/web/myFile.txt

Of course, double-check cooluser has the right to write (not just read) in that folder: 755, not 644 for the web parent folder.

4
  • buddy, how can I check If cooluser has permissions to write? I'm new to linux, very very new. Commented Feb 16, 2020 at 2:49
  • 1
    @JulioRodriguez open an ssh interactive shell session on the remote machine: ssh [email protected]. From that shell, type cd /opt/nicescada/web/, then ls -alrth. Check the line '.': (current folder), copy that line in the comments.
    – VonC
    Commented Feb 16, 2020 at 2:51
  • Buddy, I got this: drwxr-xr-x. 2 root root 24 Aug 13 2019 protected -rw-r--r--. 1 root root 2.3K Aug 13 2019 startupTemplate.htm drwxr-xr-x. 2 root root 264 Aug 13 2019 manuales drwxr-xr-x. 7 root root 138 Aug 13 2019 WEB-INF drwxr-xr-x. 34 root root 4.0K Aug 13 2019 resources -rw-r--r--. 1 root root 724 Aug 13 2019 index.jsp -rw-r--r--. 1 root root 25 Aug 13 2019 robots.txt drwxr-xr-x. 2 root root 88 Aug 13 2019 exception drwxr-xr-x. 13 root root 4.0K Aug 13 2019 . drwxr-xr-x. 15 root root 4.0K Aug 13 2019 js Commented Feb 16, 2020 at 3:05
  • 1
    @JulioRodriguez That means it is owned by root. Nobody but root can write in it. If you can ask an admin to change that web folder to cooluser (sudo chown cooluser /opt/nicescada/web), that would help.
    – VonC
    Commented Feb 16, 2020 at 3:08

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