How set PATH for root user in Debian.
hi,
In my Debian 10 laptop, I am facing a problem using fdisk command which is in /sbin. My path is Code:
test@debian:~$ su Code:
root@debian:/home/test# fdisk -l Code:
root@debian:/home/test# PATH="/sbin:$PATH" Code:
root@debian:/home/test# echo $PATH There is a file /etc/login.defs, This setting is for root and for normal users(if I am correct). If I use the command, in the middle of the file there is a path. Can I edit it? if it the right file? if yes then where may I add my path? root@debian:/home/test# vi /etc/login.defs Code:
# Code:
.profile root@debian:/home/test# ls -al Please guide me on which file may I choose to edit for permanent changes and what should I add inside it. I don't know shell scripting I just want to add the path in my root user (by switching su from normal user) so I may use fdisk or any other utility in /sbin. Thanks in advance. |
Read 'man su' and then use it properly. Spoiler: plain su will not switch the environment. This is what 'su -' does.
|
Yes if I log in through the root user then there is no issue. The thing is by using su every time I set the path root@debian:/home/test# PATH="/sbin:$PATH" I want to fix it? Is there any way?
|
Have you read what Emerson wrote above? Then read it once again. su - is your friend.
|
Thanks for guiding :)
|
I cheat. I just put the full $PATH in /etc/environment. It's unset there. Saves me time and I can do a regular su.
|
Files in /etc/profile.d are sourced by /etc/profile for system wide profile.
|
My solution to the problem, slightly edited...
Code:
root@haswell:~# cat .profile |
Thanks for the replay.I try but no success.Following is my .profile after adding ending three lines.
Code:
root@debian:/home/test# vi .profile Code:
# ~/.profile: executed by the command interpreter for login shells. Code:
test@debian:~$ su |
I don't think you still understand the difference between su and su -
With su you are still using the users path environment. Look no /sbin Quote:
Quote:
You can logout/login instead of rebooting... |
I believe /usr/local/sbin, /usr/sbin and /sbin were removed from users' $PATH at some point, in some previous release...
Just add a line similar to this to ~/.profile: Code:
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin Most of us have managed for years without destroying everything, so I don't personally see the issue with sbin directories being in users' paths. Because at times, one wants to see output from tools like ifconfig or whatever, without being root. |
As long as I've been regularly using debian /sbin has never been in a users path environment. As far as I know there is no path "standard" and while debian does not include it for a user, Red Hat does.
When root you can change everything so there is always the chance you can destroy something. |
Quote:
|
Quote:
You have to make certain it is being sourced from something and as has been mentioned the differences in how you invoke the shell switch. Put it in your normal user .profile too that way it will always be available. Code:
if [ -f ~/.profile ]; then |
Quote:
Quote:
|
All times are GMT -5. The time now is 07:48 PM. |