Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

Now, 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-inter‐ active shell with the --login option, it first reads and executes com‐ mands 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 variables 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.
share|improve this answer
    
A nice trick to self-discover this things is putting sentinel variables around. I mean, I put export SET_IN_ETC_PROFILE=yes in /etc/profile, export SET_IN_HOME_ZSHRC=yes in ~/.zhshrc (I am a zsh user), etc... Then reboot and a nice env|grep SET_IN will tell you all the story. To see which variables are seen by the desktop applications (the ones you launch from the dash or the WM, without using a terminal), see askubuntu.com/a/356973/16395 –  Rmano May 9 at 19:19
    
so when you ssh, that would be an interactive shell, correct? –  amphibient May 9 at 21:11
    
@amphibient an interactive login shell, yes. When you open a terminal on tour local machine, it's an interactive, non login shell. –  terdon May 10 at 15:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.