0

I am confused as to what this question is asking me to do. For context, hello is a c++ file.

"Use chmod command again to make hello an executable, but not readable and not writeable for all users."

Using an online chmod calculator, my best guess would be chmod 001 hello, which is executable by the public, but not readable nor writeable by the public.

Is this correct?

Rayleigh
  • 845
Matt
  • 3

2 Answers2

1

The question isn't exactly clear but my guess would be they want something like 771 or any combination of nn1. However I don't think 001 is exactly what they are looking for. They only specify that all users should be able to execute not not read or write, so there is no reason that the owner/group shouldn't be able to read/write.

Additionally if you did set the permissions to 001 you would not be able to execute, so therefore at the very least they want 111.

jesse_b
  • 37,005
1

First of all allow me to explain the basics of chmod.

Chmod is a Unix command that allows you to set permissions that determine who can access the file, and how they can access it.

You can set these permissions for 3 different categories.

  1. The owner of the file (User)
  2. The members of the group that owns that file (Group)
  3. Everyone else (Others)

There are two ways to modify the permissions:

1) By using alphanumeric characters

The permissions are separated in 3 categories:

a. Read
b. Write
c. eXecute

You can set the permissions in the following way: Let's imagine a file called file.sh We want to set the permissions so that

  • the user can read, write, execute
  • the group can read, write
  • the others can read

All we have to do is run

chmod u=rwx,g=rw,o=r file.sh

Or perhaps we want to make it executable to everyone, so we run

chmod +x file.sh

and if want the opposite of the above command we can do

chmod -x file.sh

2) By using octal numbers

The other way is by using octal numbers that each one of them represent the permissions for the user, group, and others, in that order.

  • 4 stands for "read"
  • 2 stands for "write"
  • 1 stands for "execute"
  • 0 stands for "no permissions."

By adding those numbers we can easily set the individual permissions. So if we take the previous example that would mean

chmod 764 file.sh

7 is the result of permissions 4+2+1, 6 is 4+2+0 and 4 is 4+0+0

You can view more information by running man chmod


Back to your problem. Although your question is unclear I would say you should use

chmod 711 hello

Which means you (the owner) have full permissions, your group can only execute and same goes for everyone else.

or (depending on how you interpret the words "all users")

chmod 771 hello

Which means you (the owner) have full permissions, same goes for your group but everyone else can only execute.

Now I should mention that you could use something like

chmod 001 hello

or

chmod 111 hello

but I see no point on doing something like this, unless it's a compiled program or something. But still...

Rayleigh
  • 845