[SOLVED] HOME directory is first in PATH

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Kyowash

[SOLVED] HOME directory is first in PATH

Post by Kyowash »

I've noticed my HOME directory will be the first to be searched for executable files:

Code: Select all

$ echo "$PATH"
/home/kyowash/bin:/home/kyowash/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Is this safe? Wouldn't that mean that if there's a malicious executable file with the same name as a command ($HOME/bin/ls for instance) the malicious one would be run instead?
Thanks in advance.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: HOME directory is first in PATH

Post by Flemur »

Kyowash wrote:I've noticed my HOME directory will the first to be searched for executable files:
[...
Is this safe?
It's not a good idea. It's set in your
~/.profile
file, (and /etc/skel/.profile) you can change it there (= ~/.profile = /home/username/.profile)

I was getting some bogus entries in the $PATH (/snap or something like that, and ~/.local/bin), and the ~/bin in the wrong place, so I hard-coded in the whole thing in my .profile.

You could put this line at the end of your .profile and fix everything:

Code: Select all

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/kyowash/bin:/home/kyowash/.local/bin"
Assuming you have a ~/.local/bin, which I don't.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Kyowash

Re: HOME directory is first in PATH

Post by Kyowash »

Flemur wrote:
Kyowash wrote:I've noticed my HOME directory will the first to be searched for executable files:
[...
Is this safe?
It's not a good idea. It's set in your
~/.profile
file, (and /etc/skel/.profile) you can change it there (= ~/.profile = /home/username/.profile)

I was getting some bogus entries in the $PATH (/snap or something like that, and ~/.local/bin), and the ~/bin in the wrong place, so I hard-coded in the whole thing in my .profile.

You could put this line at the end of your .profile and fix everything:

Code: Select all

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/kyowash/bin:/home/kyowash/.local/bin"
Assuming you have a ~/.local/bin, which I don't.
I have this at the end of the ~/.profile file:

Code: Select all

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
It's concatenating the variable rather than specifying the whole PATH. Would it be enough to change it to this?

Code: Select all

PATH="$PATH:$HOME/bin:$HOME/.local/bin"
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: HOME directory is first in PATH

Post by Flemur »

Kyowash wrote:I have this at the end of the ~/.profile file:

Code: Select all

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
It's concatenating the variable rather than specifying the whole PATH. Would it be enough to change it to this?

Code: Select all

PATH="$PATH:$HOME/bin:$HOME/.local/bin"
That would work - you might want to check that you have the "$HOME/.local/bin" directory.

Although apparently it doesn't matter much if there are extraneous entries in the PATH, but I often run a script which searches in the PATH and was getting error msgs about the non-existent directories I mentioned above.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Kyowash

Re: HOME directory is first in PATH

Post by Kyowash »

Flemur wrote:That would work - you might want to check that you have the "$HOME/.local/bin" directory.

Although apparently it doesn't matter much if there are extraneous entries in the PATH, but I often run a script which searches in the PATH and was getting error msgs about the non-existent directories I mentioned above.
Okay, I'll keep it in mind. Thank you for your help, Flemur.
Locked

Return to “Other topics”