0

I am running a bash script with sudo and have tried the below but am getting the error below using aws cp. I think the problem is that the script is looking for the config in /root which does not exist. However doesn't the -E preserve the original location? Is there an option that can be used with aws cp to pass the location of the config. Thank you :).

sudo -E bash /path/to/.sh
   - inside of this script is `aws cp`

Error

The config profile (name) could not be found


I have also tried `export` the name profile and `source` the path to the `config`
5
  • 1
    Have you tried to put all in the same directory(script,file to copy,etc.)? Commented Oct 13, 2021 at 22:37
  • So the script is called from one directory.... creates a bunch on new directories and copies all the new directories to aws. If I do not use sudo the aws cp is fine and returns no errors.... the problem is I need sudo to create the new directories. The original config file in $HOME/user/aws. Thank you :). Commented Oct 13, 2021 at 22:51
  • 1
    Are the new directories in a protected path? In this case cannot you add the user to the same group? Commented Oct 13, 2021 at 23:08
  • the directories are in a protected path and I do not think adding user to the same group can be done, but I will check. Short of that are there other options? Maybe I could export HOME=/root and copy $HOME/user/.aws to /root/.aws, so there are two directories with credentials. I don't think this will cause issues? Thank you :). Commented Oct 13, 2021 at 23:17
  • 1
    Yes you can also do it, or simply create a symlink from /root/.aws to /home/user/.aws Commented Oct 13, 2021 at 23:20

2 Answers 2

1

You can use the original user like :

sudo -u $SUDO_USER aws cp ...
Sign up to request clarification or add additional context in comments.

Comments

1

You could also run the script using source instead of bash -- using source will cause the script to run in the same shell as your open terminal window, which will keep the same env together (such as user) - though honestly, @Philippe answer is the better, more correct one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.