LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2019, 07:53 AM   #1
bionor
LQ Newbie
 
Registered: Dec 2019
Posts: 27

Rep: Reputation: Disabled
Issue with different PATHs for root when on non-login vs login shells in LFS build


Hey guys

First let me start off by thanking the people behind the LFS project. What an amazing project. I've learned so much doing this. I've completed the LFS book and is basically done with the BLFS as well. I've been following the LFS v9 System V and am running GNOME. I have installed Firefox, Libreoffice, VLC, Transmission and a whole lot of other stuff. My build is nearly worthy of being a daily driver as far as my laptop goes.

I have a few various small issues though. One of them is that the $PATH for my normal user and root are not the same with the path for my normal user being as it should, but root has a much smaller path variable, but only when using a non-login shell like Gterm. When I login to a TTY, like if I don't boot into the GUI, all the paths are correct.

I understand this is due to all the various bash scripts, and there are a number of them. To me this seems slightly more complicated than it needs to me.

To the best of my knowledge it seems like the scripts in /etc/profile.d are not executed for the root user when in GNOME and Gterm as it seems the missing paths are the ones found there.

My /etc/profile:
https://pastebin.com/7tJpsuDU

My /etc/bashrc:
https://pastebin.com/9FrX3hkn

An example from /etc/profile.d/extrapaths.sh:
https://pastebin.com/PMuFYVRv

The /usr/local/sbin path found here is missing when running the non-login shell from GNOME.

The ~/.bash_profile of root:
https://pastebin.com/vV85FNWg

The ~/.bashrc of root:
https://pastebin.com/FZAChB7x

The ~/.profile of root:
https://pastebin.com/VrBRx8hn

All the home directory scripts are identical for my normal user.

Output of paths for normal user:
Code:
bio@bioLinux [~]# echo $PATH
/opt/rustc/bin:/usr/local/bin:/bin:/usr/bin:/opt/ant/bin:/opt/jdk/bin:/opt/qt5/bin
Output of paths for root:
Code:
root@bioLinux[ /home/bio]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

Last edited by bionor; 12-06-2019 at 07:36 AM.
 
Old 12-06-2019, 02:50 AM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,376

Rep: Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550Reputation: 1550
I don't usually expect the PATHs of normal users and root to be the same. Yes, often a non-privileged user has a longer path.

Is this causing a problem for you? What is the problem?

You can modify the root path to be what you want in root's .bash_profile or .bashrc.
 
Old 12-06-2019, 03:38 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,599

Rep: Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358
Quote:
Originally Posted by bionor View Post
One of them is that the $PATH for my normal user and root are not the same with the path for my normal user being as it should
what do you think, how should it be set?
Quote:
Originally Posted by bionor View Post
but root has a much smaller path variable,
yes, this is normal, and not only in LFS, but in [almost] any other distro
Quote:
Originally Posted by bionor View Post
but only when using a non-login shell like Gterm. When I login to a TTY, like if I don't boot into the GUI, all the paths are correct.
You need to understand the difference between the login shell and non-login shell, also the difference between interactive and non-interactive shell.
Speaking about bash, you can see the man page (see section invocation) and you will see how are the different files are used (during start of the shell).

Quote:
Originally Posted by bionor View Post
I understand this is due to all the various bash scripts, and there are a number of them.
I do not really understand how is it related to PATH.

Quote:
Originally Posted by bionor View Post
To the best of my knowledge it seems like the scripts in /etc/profile.d are not executed for the root user when in GNOME and Gterm as it seems the missing paths are the ones found there.
gnome and other terminals execute the shell as non-login shell, but probably that can be configured.
 
Old 12-06-2019, 05:26 AM   #4
bionor
LQ Newbie
 
Registered: Dec 2019
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
what do you think, how should it be set?
Root lacks several sbin paths for instance, but only when logged into gnome and using gterm. The reason I found out about this is that I installed OpenVPN which installed into /usr/local/sbin which was not in root's path when logged in via a non login shell. Then I found out it's there if I log in directly to a console from boot. There might be supposed to be a difference between normal users and root, but not for the root user itself depending on whether you're on login shell or not, except perhaps in special cirumstances.

I've managed to resolve the issue for now though by copying this from /etc/profile into "~/.bashrc":
Code:
for script in /etc/profile.d/*.sh ; do
        if [ -r $script ] ; then
                . $script
        fi
done
As I mentioned, it seems that when using a non-login shell it doesn't read /etc/profile, which as I understand it, it should, or it could be that some of the later scripts overrides it. /etc/profile should be the first script to be read, independently of whether one's on a login or non-login shell, if I'm correct.

Quote:
Originally Posted by pan64 View Post
You need to understand the difference between the login shell and non-login shell, also the difference between interactive and non-interactive shell.
Yes, I do. I tried to inform of that by specifying that the difference seems to be between login shells and non-login shells, but I could have made that clearer perhaps.

EDIT: I've changed the title of my OP to better reflect the actual issue.

Last edited by bionor; 12-06-2019 at 07:35 AM.
 
Old 12-08-2019, 03:45 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,290

Rep: Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592
It's a pity that graphical logins no longer behave like logins.
They do not run /etc/profile and .profile
These should run once - at login.
Some distros take care, e.g. by running /etc/profile from /etc/bash.bashrc
If that's not the case in your distro then I suggest to run /etc/profile in your .bashrc
The /etc/profile should run the /etc/profiles.d/ files.
Code:
if [ -z "$MY_PROFILE_RUN" ]
then
  export MY_PROFILE_RUN=1
  . /etc/profile
fi
The environment variable ensures that it is run once.
(Some distros have such a variable in /etc/profile ...)

Last edited by MadeInGermany; 12-08-2019 at 04:56 AM. Reason: typos
 
1 members found this post helpful.
Old 12-08-2019, 05:23 AM   #6
bionor
LQ Newbie
 
Registered: Dec 2019
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
It's a pity that graphical logins no longer behave like logins.
They do not run /etc/profile and .profile
Oh really? Well that explains it. I was told /etc/profile was the first one to be run independently of login vs non-login. Thanks! I'll mark it as solved now.
 
Old 12-08-2019, 05:49 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,599

Rep: Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358Reputation: 4358
Quote:
Originally Posted by bionor View Post
Oh really? Well that explains it. I was told /etc/profile was the first one to be run independently of login vs non-login. Thanks! I'll mark it as solved now.
That is false.
Quote:
(man bash)
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.
During graphical login there will be no bash invoked as interactive login shell. But anyway, you can tell your terminal to run bash with --login.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible that normal user should not able to remove crontab which was set by superuser for this normal user? gjoshi Linux - Newbie 1 04-02-2019 01:30 AM
getting differing rusult between command line and script nix84 Programming 3 06-24-2016 11:53 PM
How to get root user PATH from normal user nagendrar Linux - Newbie 11 08-23-2011 09:40 PM
usb-storage problem with differing devices ta0kira Slackware 1 11-14-2004 01:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration