Score:0

bash: permission denied, Owncloud helper script

nz flag

I don't know to much about linux and server creating but I wanna create my private owncloud web drive, I have linux Ubuntu 20.04 server on my Raspberry pi4 installed. I have started using this tutorial to set it up but I'm having issues at the beginning. When I'm trying to create Helper Script(?):

Create the occ Helper Script

Create a helper script to simplify running occ commands.

FILE="/usr/local/bin/occ"
/bin/cat <<EOM >$FILE
#! /bin/bash
cd /var/www/owncloud
sudo -E -u www-data /usr/bin/php /var/www/owncloud/occ "\$@"
EOM

Make the helper script executable:

chmod +x /usr/local/bin/occ

In my terminal I get this kind of error:

Terminal screenshot

How make it work?

Kulfy avatar
mz flag
`/usr/local/bin/occ` is owned by root. The article clearly mentions, ***"This guide assumes that you are working as the root user."*** You may consider logging in as `root` temporarily or `sudo` (note that sometimes `sudo` may not work, for example, with shell builtins).
muru avatar
us flag
Please don't post screenshots of text. Copy the text here and use code formatting for commands and command output, please.
Score:0
sa flag

This is crazy, the tutorial uses ubuntu, where 'root' isn't usable directly, it then assumes you have logged in as root.

Either wrap the code in another script and run that with sudo, or extract the three lines for the script from the code and create the script directly with an editor. If you do the latter, remove the '' from the last line i.e. "\$@" becomes "$@"

Score:0
us flag

If you're getting a permission denied error, you can try this instead:

FILE="/usr/local/bin/occ"
sudo tee "$FILE" <<'EOM'
#! /bin/bash
cd /var/www/owncloud
sudo -E -u www-data /usr/bin/php /var/www/owncloud/occ "$@"
EOM

This will run tee with sudo, which should allow writing to the /usr/local/bin/occ file. (See How to solve "permission denied" when using sudo with redirection in Bash?) Then you can use the chmod command with sudo as well.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.