How can I display the welcome message "welcome panni" every time I log into unix?
5 Answers
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.
-
1Sure. 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.– MarceloCommented Dec 7, 2014 at 14:23 -
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.
-
4Other monsters are false monsters, undeserving of capitalization!– AnthonCommented Dec 7, 2014 at 12:57
-
11
If you allow access via SSH, you can specify a banner file in /etc/ssh/sshd_config using the Banner directive.
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?
-
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 thewhoami
command in the/etc/profile
script as in my answer.– MarceloCommented Dec 7, 2014 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 Commented Dec 7, 2014 at 13:07
-
Maybe, but this is not what the "welcome" word suggests... (and yes, of course it is...)– MarceloCommented Dec 7, 2014 at 13:11