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.
#!/usr/bin/env perl use strict; use warnings; my $ip = (split / /, $ENV{SSH_CLIENT})[0]; if ($ip eq 'xxx.xxx.xxx.xxx') { print "Hello XXXXn"; } else { print "Hello from unknown IPn"; }
Then you need to execute this script at login time. You can do this by calling the script from the end of /etc/profile
.