0

I have Ubuntu 12.04.5 LTS.

In terminal I performed:

/etc/profile

Thus returns permission denied.

This surprised me as I had run the sudo -s command and my command prompt started with root@...

What's the reason for this?

1
  • 3
    This question is not version-specific, so should not be closed imho, but please consider upgrading to a supported release. We do not support EoL versions of Ubuntu here.
    – Zanna
    Jan 24 '18 at 22:02
5

The default permissions of /etc/profile are

-rw-r--r-- 1 root root 575 Okt 22  2015 /etc/profile

This means that the file is readable with commands like

cat /etc/profile

but not executable like

/etc/profile

as you tried to do (executing it). Because the executable permissions bit is not set, even with superuser permission this will fail and create the "Permission denied" message. As mentioned in the comments, it generally is no good idea to change the permissions in /etc because of security concerns, so if you really need to execute it, use the source command like this:

source /etc/profile
1
  • 2
    Agree with @guntbert, and you should explain in your answer that there is no reason to execute /etc/profile with the command /etc/profile. Presumably OP wanted to read the file, but if they wanted to execute the file in the current shell (which is reasonable, as it is a configuration file for shells), that would be done with the source command, and permissions will not be a problem - you are allowed to source files you can read, and that executes them in the current shell. source is therefore a pretty dangerous command - make sure you know what is in the file before you source it!
    – Zanna
    Jan 24 '18 at 22:00
5

It is because by default that file doesn't have any executable bits set. Even root cannot execute a file that is not executable for any user.

ls -l /etc/profile
-rw-r--r-- 1 root root 1722 Jan  6 20:09 /etc/profile

/etc/profile is there to be sourced at login, and sets the environment. Do less /etc/profile and you will see exactly what it sets.

By default, most of the regular files in /etc have permissions 644 which in symbolic notation is rw-r--r-- and means the file owner can read and write to it, members of the group can only read the file, and others (any user or program) can only read the file.

0

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