I have big problem after mounted hard driver in my server every thing was working fine but after i tested execute bash file in bash file was working before mounted but after mounted it says permission denied in root mode .

ls -alt /var/www/test/bin/change-sys-hostname
-rwxrwx--- 1 www-data www-data

My code in example.sh

/var/www/test/bin/change-sys-hostname $servername

result :

permission denied
  • 2
    You're not clear that you are attempting to run this script from commandline, or web client. The answer depends on knowing this.
    – somebody
    Jun 17, 2019 at 20:26
  • 1
    Also what web server are you running?
    – somebody
    Jun 17, 2019 at 20:28
  • 2
    What does /var/www/test/bin/change-sys-hostname do, and what is the value of $servername?
    – roaima
    Jun 17, 2019 at 22:22
  • 1
    Please could you write your (single) sentence more clearly. I mentally ran out of breath trying to understand what you were saying. Break it up! Amongst other things you should explain what you want, what happened, what didn't happen, why this is wrong, and what you've done to attempt to mitigate the issue. If you take a little care over asking your question it should be easier for people to help you with your issue.
    – roaima
    Jun 17, 2019 at 22:24
  • 1
    Please proof-read and edit: I just read it. It appears to be a lot of words, but I need sentences. Have one idea per sentence. Keep it simple. e.g. ”I have a big problem. After mounting the hard drive, everything was working fine. However …” Jun 17, 2019 at 22:39

1 Answer 1


Permission denied means that you are attempting something that is not allowed. Your question lacks some basic information that is needed to determine what exactly is not allowed.

To start at the beginning: example.sh. How are you running this script? As bash examle.sh? as ./example.sh? If the latter: your script must be executable by you. Is the script executable by you? Use ls -l to verify that.

As a side note: you should start your script with the line


to be sure that bash is used to execute it.

Second side-note: $server should be set. It may be set in your shell's environment, but you must be sure. However: not having set $server to some correct value will probably give a different error message. You might echo the value of $server just to be sure.

Next: can you execute /var/www/test/bin/change-sys-hostname? The script is executable by the group www-data. Are you in that group? Check with id if www-data is in your group-set.

Next is whether change-sys-hostname has something in it that you are not allowed to do. change-sys-hostname will probably call some other programs as well, which you should be allowed to execute. Especially: the script will probably write to some files that are only writable by root. So, sudo will probably be required.

I've gone through some basic steps that you will need to do to find the solution. You will notice, that a lot of information in those steps is not in your question, and that information is needed to assess what is going on.

  • Assuming that we're trying to fix a problem and not diagnose it, we should probably use clarifying comments to ask questions of the OP, and not an Answer. Given that there aren't any real questions in the Question, we're both going out on a limb to figure out what they want. Just thought I'd point it out, going forward. Thanks!
    – Jeff Schaller
    Jun 19, 2019 at 13:29
  • Yes. But the size of comments is too small to ask for all the required missing extra information. So I abused an answer for it. Jun 19, 2019 at 19:45

Your Answer

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

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