I wrote a script that should allow me to create directories with specific permissions on a remote server.

I used the command to execute the script to the remote server:

[email protected] /root/Documents/script

And I got this answer:

bash: /root/Documents/script: Permission denied
Connection to closed.

I'm working on Fedora 20, and the server is on Ubuntu 18.04.1.

I tried to modify the permission on my script document with chmod:

chmod 777 script

At first I tried to execute the script with the SSL connection integrated inside of the script (you can see it in my script).


#Connecting to Ubuntu Server
#ssh [email protected]

#specifying the directory where I want to create my two directories
cd /home/stan

#Creating the first directory "PublicFolder" and assigning permissions
mkdir PublicFolder
chmod -R 606 PublicFolder

#Creating the first directory "PrivateFolder" and assigning permissions
chmod -R 604 PrivateFolder
  • Possibly unrelated: There seems to be a mkdir missing on the penultimate line of that script.
    – Kusalananda
    Feb 18, 2019 at 19:47
  • Kusalananda, you're right. It's in my script though, I guess I deleted that line by mistake while I was editing my post. I'm sorry about that. Thank you!
    – Pak
    Feb 18, 2019 at 19:52
  • Does the user stan have access to the script at all on the server? The /root directory is usually (and should be) inaccessible by non-root users.
    – Kusalananda
    Feb 18, 2019 at 20:00
  • I would expect bash: [email protected]: command not found. Feb 18, 2019 at 20:11
  • 1
    I found the answer: I executed this command on my local machine: ssh [email protected] 'bash -s' < script . I don't really know why it works yet, but I'll work on that! Thank you very much for all of your answers.
    – Pak
    Feb 19, 2019 at 0:35

1 Answer 1


I see a few possibilities that could be causing your issue. 1. There is no ssh in front of your command. Try this:
ssh [email protected] /root/Documents/script
2. you are logging in to the remote server as stan and trying to execute a script that is under the user root. Stan will not have access to this script, even if you change the permissions on the file script.
3. Permissions flow down the directory tree with the x attribute. By default, /root will not allow access to anything below it.
ssh [email protected] ls -ld /root
ssh [email protected] ls -ld /root/Documents
You will probably see something like this:
drwxr----- root root /root
Or, more likely, you will get a permission denied error, because stan can't see in to /root.
BAD root: # chmod -R a+rx /root
Better move /root/Documents/script /tmp & set execute permissions on /tmp
BEST cread a directory called /share, move /root/Documents/script to /share and set r+x permissions on /share

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .