In Ubuntu, I added file under /etc/update-motd.d/


IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 1)

if [ "$IP" = ];    then 
    printf "\nHi Frank\n"
elif [ "$IP" = ];  then 
    printf "\nHi, Eliot. Nice to see you!!\n"
    printf "\nWho are you?\n"

It does not working because echo $SSH_CONNECTION had not ready when motd executed.

How can I resolve it?

  • You may be able to change the file on each login via the sshd ForceCommand option or PAM. Commented Aug 17, 2017 at 19:05

1 Answer 1


You can't.... the motd is a static file... Ubuntu has an update-motd tool which periodically regenerates this file, but there is no way to do anything related to a connection using the motd.

You can probably include something equivalent in the /etc/profile... which is run after someone logs in.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .