Question regarding the PATH


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question regarding the PATH
# 1  
Old 10-12-2005
Question regarding the PATH

"Never put the current directory (specified by . (period)) in the PATH value specified for the root user. Never allow the current directory to be specified in /etc/profile. The root user should have its own PATH specification in his private .profile file "

Infos: Refer: http://publib.boulder.ibm.com/infoce...r_accounts.htm

My question is, what is actually the PATH is? what it keeps inside the PATH?
and what is the .profile?

So, based on the statement above(the blue colour font), can you rephrase the statement in easy way to understand?

Last question, is every user will have their own path?

Kind Regards,
Rizwan
# 2  
Old 10-12-2005
1. What is the PATH?
I got the below definition from this site.
PATH
The PATH variable contains the names of directories to be searched for programs that correspond to command names. When you issue a command to the shell, the shell searches sequentially through each directory in the PATH list until it finds an executable program with the command name you typed.
I think that this makes things quite clear.

2. What is kept in the path?
Continuing from the answer of the first question, this list is a colon ':' seperated list of directories. So a user's path can look like this:
$ echo $PATH
/usr/bin:/usr/local/bin

You can set the path in sh,ksh and bash in the following manner:
$ PATH=/usr/bin:/usr/local/bin:/usr/ucb; export PATH
OR
$ PATH=$PATH:/usr/ucb; export PATH # this will set the new path to whatever the old path was and the directory /usr/ucb

3. What is the .profile?
Now you may not want to manually set the path in the above manner every time you login - maybe you want to automate this. This can be done using the .profile file. This is a file that is present in every user's home directory. It contains various settings that the user wants to personalize. This file is read when the user logs in using sh/ksh and the variables in the file are set in the environment. So if you write a 'PATH=..; export PATH' statement in the file, then the PATH is set for you during your login.

5. Every user does have his own path. The variable may have the same value as some other users' path, but it is handled seperately for each program that the user runs.

I saved the 4th question for last:
If you (root) specify the PATH variable as follows:
PATH=/usr/bin:.:/usr/sbin:/sbin:/usr/local/bin
and you run a command such as mount which is in /usr/sbin, then your shell will look through the directories in your path in the order of '/usr/bin', '.' (which is the current working directory), and then '/usr/sbin' where it will find the mount command.
But note that the '.' is searched very early on. If you are working from the /tmp directory, and a hacker keeps a shell script called mount in that directory, then the shell script /tmp/mount will be executed as the shell will find that first - so /usr/sbin/mount is never run. Now in this shell script, the hacker may have written anything that (s)he wants and whatever commands are in there will run with root privileges.

That is what the statement in blue means. Do not set the '.' (current working directory) in the root's path. And have a line in the root's .profile file set the PATH variable without using any prior PATH value.
i.e. the variable should be set as:
PATH=/usr/bin:/usr/sbin:/sbin; export PATH
and not as:
PATH=$PATH:/usr/sbin:/sbin; export PATH
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

2. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

3. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

4. OS X (Apple)

Newbie PATH command question...

Still trying to pick up speed on the command line in OSX. I have installed Apache, and some other server software, but am having problems getting my install of Perl to work. I feel like it's because my Apache install is looking for the base (built-in) Perl that came with OSX which is 5.10. I... (4 Replies)
Discussion started by: Bridger
4 Replies

5. Shell Programming and Scripting

Question on tweaking the PATH variable to allow the world to run my executable script

All, I am pretty new to Unix and still in the learning curve :) I have a simple requirement for which I did not get an answer yet (Atleast I do not know how to keyword the search for my requirement!!!). I have an executable script my.script1 in a folder /data/misc/scripts/dev, which when... (5 Replies)
Discussion started by: bharath.gct
5 Replies

6. Shell Programming and Scripting

Executing Commands From Non-Standard Path (Changing user's PATH secretely???)

Hi: I have a requirement as below: I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l). When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies

7. SuSE

PATH question

How does one decide where to un-zip a tar file ? I've downloaded one and placed it in my own directory but it has created USR and various sub libraries such as BIN. In trying to run the executable, I'm getting hercules: error while loading shared libraries: libherc.so: cannot open shared... (6 Replies)
Discussion started by: stansaraczewski
6 Replies

8. AIX

stupid question: the path

I'm sorry for my stupid question, but when I log in with one account on my AIX machine, I see: psar3@caixpc24: /home/psar3 > > When I login with another login (pger1), I see: caixpc24 # how can i change that i see the same for pger1 as for psar3??? (it's easy to see with which... (4 Replies)
Discussion started by: Leilah
4 Replies

9. HP-UX

Question about the hareware path and device name

# ioscan -f | grep disk Class I H/W Path Driver S/W State H/W Type Description disk 3 0/0/2/0.0.0.0 sdisk CLAIMED DEVICE TEAC DV-28E-N disk 1 0/1/1/0.0.0 sdisk CLAIMED DEVICE HP 146 GST3146707LC ... (1 Reply)
Discussion started by: bluepluto
1 Replies

10. UNIX for Dummies Questions & Answers

Question about Restricting Search path of FIND to current directory

Hi, By default FIND command searches for matching files in all the subdirectories within the specified path. Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories. Any help would be more than appreciated. Thanks and Regards (2 Replies)
Discussion started by: super_duper_guy
2 Replies
Login or Register to Ask a Question