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:

stan@ /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 stan@

#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 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 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 at 20:00
  • I would expect bash: stan@ command not found. – ctrl-alt-delor Feb 18 at 20:11
  • 1
    I found the answer: I executed this command on my local machine: ssh stan@ '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 at 0:35

I see a few possibilities that could be causing your issue. 1. There is no ssh in front of your command. Try this:
ssh stan@ /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 stan@ ls -ld /root
ssh stan@ 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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