33

How can I display the welcome message "welcome panni" every time I log into unix?

Zanna
  • 3,491
  • 18
  • 28
panni
  • 369
  • 1
  • 4
  • 5

5 Answers5

48

Normally, a welcome message can be shown by customizing the /etc/motd file (which stands for Message Of The Day). /etc/motd is not a script but a text file which contents are shown before the first prompt of a login session.

You can also add some messages in /etc/profile or /etc/bashrc scripts using the echo or print commands (note that the /etc/bashrc assumes you are using the bash shell).

Here are examples of commands that can be added to /etc/profile file to obtain a result like the one you expected:

echo "Welcome ${USER}"

or

echo "Welcome $(whoami)"

OBS1: If the system is correctly configured, the results of the above should be the same, but the ways they work are different: The first one shows the $USER environment variable while the second executes the command whoami.

OBS2: Note that the /etc/profile is ran once per session and only for login shells. This means that the message will be shown when the user logs in in the console or rsh/ssh to the machine, but not when he/she simply opens a terminal in an X session, for example.

Marcelo
  • 3,401
  • 17
  • 21
  • 1
    Sure. BTW, adding a standalone script under `/etc/profile.d` directory as goldilocks suggests in his answer may be a better approach than editing `/etc/profile` directly, but this solution really depends on the unix flavor and how recent it is. In both approaches, using the ${USER} and the $(whoami) to identify the user should work, BTW. – Marcelo Dec 07 '14 at 14:23
  • Good answer. Might link to [motd (5)](http://man.flashnux.com/en/centos/5/5.5/man5/motd.5.html). – Charles Stewart Dec 07 '14 at 16:15
14

Create a file in /etc/profile.d called greeting.sh or whatever you like. It does not need to be executable or contain a shebang. You need one line:

echo "Hello World"

You could also use:

echo "All Hail the Flying Spaghetti Monster!"

Etc.

If you don't want to do this for every user, add it to ~/.profile or ~/.bash_profile, whichever works on your system.

goldilocks
  • 86,451
  • 30
  • 200
  • 258
12

Befor login

/etc/issue
/etc/issue.net

After login

/etc/motd
PersianGulf
  • 10,728
  • 8
  • 51
  • 78
Fakari Ali
  • 129
  • 2
6

If you allow access via SSH, you can specify a banner file in /etc/ssh/sshd_config using the Banner directive.

fpmurphy
  • 4,556
  • 3
  • 23
  • 26
3

That is called message of the day, or motd in short. It's located under /etc. Also see http://en.wikipedia.org/wiki/Motd_%28Unix%29 and there should be a man page on your unix system, you should have a look with man motd. For your example, simply set it up via
echo welcome krishna >> /etc/motd and try another login.

There are also many threads here related to motd details:
How do I use colors in the MOTD?
Change motd value in UNIX Operating System
Motd doesn't show up

For more details, what unix flavour do you use, so people can maybe provide some hints for specific configurations related to that specific unix flavour? Or, as your question is tagged with #linux, is it about linux and motd in general? Also, how do you login?

doktor5000
  • 2,689
  • 15
  • 30
  • I don't believe panni wants the "hello krishna" message hard coded for every user, but just for krishna. Better using the `USER` environment variable or the `whoami` command in the `/etc/profile` script as in my answer. – Marcelo Dec 07 '14 at 12:58
  • Hmmm, maybe it was just a typo and he wants to display "Hare Krishna" to all users logging in, would your solution be able to do that? :p – doktor5000 Dec 07 '14 at 13:07
  • Maybe, but this is not what the "welcome" word suggests... (and yes, of course it is...) – Marcelo Dec 07 '14 at 13:11