Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  66] [ 0]  / answers: 1 / hits: 51011  / 12 Months ago, wed, may 31, 2023, 2:27:56

I would like to concentrate all my login config in my ~/.bash_profile. There was a ~/.bashrc there by default but I replaced it with a ~/.bash_profile.



However, when I log in, something before my ~/.bash_profile gets sourced and displays the following:



Linux ubnt10-dev1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS

Welcome to the Ubuntu Server!
* Documentation: http://www.ubuntu.com/server/doc

System information as of Fri May 9 12:17:39 EDT 2014

System load: 0.01 Processes: 74
Usage of /: 5.5% of 18.58GB Users logged in: 0
Memory usage: 4% IP address for eth0: 123.x.x.x
Swap usage: 0%

Graph this data and manage this system at https://landscape.canonical.com/

New release 'precise' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Fri May 9 12:11:52 2014 from 123.x.x.x


I would like to remove that so that only my own splash greeting defined in my ~/.bash_profile gets displays but I am not sure about the logic/sequence of scripts sourced/executed when a user logs in. Can you enlighten me?



As a bonus, I would also like to know the sequence of automated sourcings/execs when the system starts, not just when a user starts a session by logging in, albeit this is a concern of lesser importance to me right now.


More From » bash

 Answers
7

This is kind of complex. First of all, the details depend on what kind of shell you are running. To plagiarize myself:




  • When you open a terminal emulator (gnome-terminal for example), you are executing what is known as an interactive, non-login shell.


  • When you log into your machine from the command line, or run a command such as su - username, you are running an interactive login shell.


  • When you log in graphically, you are running something completely different. The details will depend on your system and graphical environment but in general, it is the graphical shell that deals with your login. While many graphical shells (including the Ubuntu default) will read /etc/profile and ~/.profile not all of them do.


  • Finally, when you run a shell script, it is run in a non-interactive, non-login shell.




The files that bash will read when launched depend on the type of shell it is running as. The following is an excerpt of the INVOCATION section of man bash (emphasis mine):




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. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order
, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.



When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be inhibited by using the --norc option.
The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.




Those are the initialization files. You also have /etc/environment where you can set global environmental variables but that's read rather than sourced (commands inside it are not executed but variable definitions are set).



Now, the greeting you see is something else again. That is set in /etc/motd and is displayed through pam_motd. As explained in man motd:




The contents of /etc/motd are displayed by pam_motd(8) after a
successful login but just before it executes the login shell.



The abbreviation "motd" stands for "message of the day", and this
file has been traditionally used for exactly that (it requires
much less disk space than mail to all users).



On Debian GNU/Linux, the content of /run/motd.dynamic is also
displayed. This file is generated by /etc/init.d/motd at boot.




To remove the message just empty the /etc/motd file and make sure that nothing is being generated by /etc/init.d/motd if present.






Anyway, based on the output you show, you seem to be logging in via ssh which means you're running an interactive login shell, see above for what that means.
So, in summary, the things you care about that are sourced when you log in are (and in this order):




  1. The SSH daemon, via the pam_motd module of the PAM library, displays the contents of /etc/motd. Via the pam_env module, it sets the environment variables from /etc/environment and ~/.pam_environment.

  2. A login shell is started, and the following files are read in order:


    1. /etc/profile

    2. /etc/bash.bashrc (the default Ubuntu /etc/profile sources /etc/bash.bashrc).

    3. ~/.bash_profile. The other files that could have been read here (~/.profile and ~/.bash_login) are ignored because ~/.bash_profile exists.



[#25323] Friday, June 2, 2023, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trousransla

Total Points: 285
Total Questions: 112
Total Answers: 113

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;