Skip to content
Advertisement

In Unix, how to display welcome message if user has logged in from a particular IP (or host)?

I want to display one message if user XYZ has logged in from any IP (or host).

Advertisement

Answer

Check to see if you have environment variables such as SSH_CLIENT and SSH_CONNECTION set. If so, you can access these from scripts (perl, bash, etc…) to dynamically generate a welcome message. Below, is a simple perl script to extract the IP address from env var SSH_CLIENT and output a welcome message.

JavaScript

Then you need to execute this script at login time. You can do this by calling the script from the end of /etc/profile.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement