I have a ubuntu server to which I login as admin which can do sudo . On this server I have created dir /opt/myapp. I had to do sudo mkdir otherwise it would not work. Now from my desktop I want to do:
scp myfile admin@example.com:/opt/myapp
but I get Permission denied. But if I
scp myfile admin@example.com:
works fine and myfile is in /home/admin directory.
How to solve this problem?
Best Answer
First... maybe this is not a good idea. It may be that the permissions are set this way to stop people from doing exactly what you are trying to do for some good reason. That said, you are the captain of your destiny.
Find out who can write to that dir. Do:
and you will get something like:
Potential Option 1: switch to the user account that is built for that app. eg:
But you likely do not have the password for that user. Potentially, you can solve that by authenticating with a key. https://www.techrepublic.com/article/how-to-use-secure-copy-with-ssh-key-authentication/
Potential Option 2: Change the permissions of the dir '/opt/myapp' to 774 (or 770)
Then make the admin user a member of the group that now has write permissions. https://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/ This one is not great as you may run into trouble with being blocked from over-writing files (depending on what is going on).