Search code examples
linuxbashredhat

/etc/profile is a directory


On my RHEL8, the /etc/profile is a directory rather than a file therefore when starting a ssh connection with the computer, I get bash: /etc/profile: is a directory. I can see the directory there as I can cd into it and it contains multiple .sh or .csh files. I can also locate the profile file inside it indicating the executing path should be /etc/profile/profile rather than /etc/profile.

The reason that I need to fix this issue is because I want to put customised shell files in the /etc/profile.d directory but it is only called when /etc/profile is actually called. In this case, it isn't called because of the /etc/profile is directory error.

I have tried to do sudo cp /etc/profile/profile /etc/profile to see if I copy the file path to /etc directory will work; however, I get cp: '/etc/profile/profile' and '/etc/profile/profile' are the same file.

Helps will be greatly appreciated!


Solution

  • On my RHEL8, the /etc/profile is a directory rather than a file

    I don't know how that situation arose, but it is not normal of RHEL8 and not correct with respect to RHEL's default shell, Bash.

    I can see the directory there as I can cd into it and it contains multiple .sh or .csh files.

    Are you sure you're not looking at /etc/profile.d? On RHEL, Ubuntu, and some other distributions, that is indeed a directory such as you describe.

    I can also locate the profile file inside it indicating the executing path should be /etc/profile/profile rather than /etc/profile.

    I take that instead as an indication that your system configuration has been mangled. It's impossible for me to say whether that was intentional or accidental, and if intentional, whether it was meant to be beneficial or malicious. In any case, it has evidently had some unwanted effects.

    I have tried to do sudo cp /etc/profile/profile /etc/profile to see if I copy the file path to /etc directory will work; however, I get cp: '/etc/profile/profile' and '/etc/profile/profile' are the same file.

    To get back to a standard configuration, rename directory /etc/profile to something else, say /etc/profile.oops. Then move the profile script out of it to its normal position: sudo mv /etc/profile.oops/profile /etc/profile.

    But be well aware that depending on how this issue arose, there may be other issues that need to be resolved. For example, it might be that some of the scripts presently in your /etc/profile directory ought to be in /etc/profile.d instead. Might. Or if the change was associated with the machine having been compromised by a malicious adversary then your best bet would probably be to perform a complete wipe and reinstallation.