0

I have used chmod to make all the contents of a directory executable. However, when I try to run one of the programs in that directory as a regular user (me), I get a "command not found" message. If I run as su, the programs run. What am I missing? I am running Fedora 22. Here is a complete bash session. (It's also showing that my git installation is incomplete, but I think that's irrelevant.)

bash: home/brian/git-completion.bash: No such file or directory
bash: /home/brian/git-prompt.sh: No such file or directory
bash: __git_ps1: command not found...
brian ~ $ ipython
bash: ipython: command not found...
Similar command is: 'python'
bash: __git_ps1: command not found...
brian ~ $ su
Password: 
bash: home/brian/git-completion.bash: No such file or directory
bash: /root/git-prompt.sh: No such file or directory
bash: __git_ps1: command not found...
root brian $ ipython
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 17:02:03) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 

In addition, here is a complete listing of my .bashrc:

sudo# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Enable tab completion
source home/brian/git-completion.bash

# colors!
green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
reset="\[\033[0m\]"

# Change command prompt
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# '\u' adds the name of the current user to the prompt
# '\$(__git_ps1)' adds git-related stuff
# '\W' adds the name of the current directory
export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"

# added by Anaconda 2.3.0 installer
export PATH="/root/anaconda/bin:$PATH"
BrianM
  • 11
  • 1
    I think you're making a mistake as the error you get does not concern permissions. Please post all your output. – dr_ Aug 18 '15 at 14:31
  • Try running the command with the relative path ./command_name – primero Aug 18 '15 at 14:35
  • 1
    Do regular users have read and execute permissions on the directory itself (and all parent directories)? If the user's don't have execute on the directory they can't access any of the files in it, even if they would have permission for that file--they can't get to it. – Eric Renouf Aug 18 '15 at 14:39
  • 1
    Also, the changes to permissions made by the chmod command are always permanent -- whether you are a privileged or an unprivileged user. – dr_ Aug 18 '15 at 14:41
  • 1
    You have an unsafe path for root. Probably got the current directory in it. – Ed Heal Aug 18 '15 at 17:43
  • Could you explain about the unsafe path? I have always been a bit confused about how Fedora has a /root directory at what I think of as the root level. – BrianM Aug 18 '15 at 17:51

2 Answers2

1

This looks like it has nothing to do with permissions. You'd see a "permission denied", not a "command not found".

What's going on is that you seem to have . in your $PATH as root (which is insane), but not for your own account.

Is it safe to add . to my PATH? How come?

Answer: no. You unpack a tar.gz, cd into the directory, and run ls. There's an executable in the directory called ls, which runs instead of /bin/ls. It modified your ~/.bashrc so the next time your run su and type in the root password, the attacker owns your machine.

If you want to run something in the current directory, run ./cmd

Peter Cordes
  • 6,466
  • I think I get it. Now for a very practical and dumb question: where do I find the 2 paths (mine as user and root) to change them? – BrianM Aug 19 '15 at 14:15
  • @BrianM: Usually they're set in your ~/.bash_profile or ~/.bashrc. Root has its own versions of those files, if you're using su instead of sudo. (Root's home directory is /root. Don't be confused by / being called the root filesystem; that's the root-of-the-tree sense, rather than the root user.) – Peter Cordes Aug 19 '15 at 14:23
  • I realize we shouldn't be communicating so much via comments but I don't yet have chat privileges. The two .bashrc files are identical''' sudo# .bashrc alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' . /etc/bashrc fi source home/brian/git-completion.bash green="[\033[0;32m]" blue="[\033[0;34m]" purple="[\033[0;35m]" reset="[\033[0m]" source ~/git-prompt.sh export GIT_PS1_SHOWDIRTYSTATE=1 export PS1="$purple\u$green$(__git_ps1)$blue \W $ $reset"

    added by Anaconda 2.3.0 installer

    export PATH="/root/anaconda/bin:$PATH"

    – BrianM Aug 19 '15 at 14:42
  • Sorry for the messy formatting of the previous comment. Please see the edited OP for the .bashrc. Question: what should be changed where? I was never aware of the multiple paths. Thanks for that info (and all your help) – BrianM Aug 19 '15 at 14:56
  • @BrianM: There are several places PATH can be modified. Google should point you in the right direction. – Peter Cordes Aug 19 '15 at 15:17
0

The issue turned out to be neither a PATH nor a permissions problem. Anaconda Python was installed in my /root directory, which meant that it could only be accessed by a superuser. Reinstalling Anaconda in home solved the problem.

BrianM
  • 11