-1

I wrote a very simple 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@192.168.159.133 /root/Documents/script

And I got this answer:

 bash: /root/Documents/script: Permission denied
 Connection to 192.168.159.133 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).

I tried to read several posts, but for most of the answers my knowledge is still too weak to understand everything.

#!/bin/bash

#Connecting to Ubuntu Server
#ssh stan@192.168.159.133

#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
PrivateFolder
chmod -R 604 PrivateFolder
Pak
  • 157
  • 1
  • 1
  • 6
  • 5
    I'm voting to close this question as off-topic because it squarely sits in the realm of https://unix.stackexchange.com ... – tink Feb 18 '19 at 17:59
  • Ok, I'm sorry, I didn't know where to post it. – Pak Feb 18 '19 at 18:03
  • 1
    Which is why I'm telling you ;) ... all good. – tink Feb 18 '19 at 18:05
  • Yes of course, I understand ! Thank you for the tip ! – Pak Feb 18 '19 at 18:09
  • 1
    **DO NOT EVER `chmod 777`**. Not under any circumstances whatsoever. It's better that your program not work at all than that you open a security hole that lets *every single user on the system*, including completely untrusted accounts like `nobody` (which is used, f/e, to sandbox code handling unauthenticated network connections), modify a script that another user is then going to be executing. – Charles Duffy Feb 18 '19 at 18:29
  • 1
    ...that said, if `/root/Documents` or `/root` isn't accessible to the account you're trying to run this as, it doesn't matter what the permissions for `/root/Documents/script` are; `+x` is needed on the parent directories in order to traverse them. This thus explains why `chmod 777` wouldn't be helping you. (Now, the thing you *absolutely must not* do is then `chmod 777 /root /root/Documents`; that would fix the narrow problem, but break the ability to ssh into root (since sshd sanity-checks permissions to files it trusts) and, again, break your system's security model entirely). – Charles Duffy Feb 18 '19 at 18:31
  • Thank you Charles, I will definitely remember what you just said. I'm just practicing and trying to learn, nevertheless, I will never do that again. Thank you very much. – Pak Feb 18 '19 at 19:46

1 Answers1

1

I will not comment on the permission settings in the script, even though they seem strange to me. I will not comment om the 777, because that has already been done.

When you get a permission denied, that can be because the script cannot be executed or because something in the script refuses to execute. Your error message suggests the first.

First of all: can you read the file? Try cat /root/Documents/script. If you cannot read it, you should make sure that you can. That would probably mean that you will need to put the script elsewhere (not under root's home directory), because of lots of reasons (see comments Charles Duffy).

If you can read the file, you might try bash /root/Documents/script to execute it. If that works, just chmod a+x the file to get it executable.

So why is the script in /root/Documents? Seeing the content of the script, I would expect it under /home/stan/scripts, or something like that. In that way, you can always change its permissions, read it and even make sure you execute it.

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31