Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to run script upon initial login over SSH that displays some helpful information to the user logging in. However, I don't want this script to run on every login. That is, if the user starts screen after logging in the custom "motd" shouldn't be run again (nor if subsequent screens are created). Of particular note, the script will need the user's final ENV to work correctly. Is this possible? If so, how do I go about doing it?

share|improve this question
add comment

2 Answers

PrintMotd directive is not allowed within a Match block. If all you want is display some helpful info for a specific user when he login, Banner directive can do this:

Match User <special_user>
    Banner /etc/ssh/banner.txt
share|improve this answer
1  
He mentioned using the user's env in a script to print this info, does banner support that? I didn't think it did. –  polynomial Sep 13 '11 at 6:26
    
Indeed. I want to execute a script, not dump a text file to the screen. –  jsumners Sep 13 '11 at 12:47
add comment
up vote 2 down vote accepted

As outlined in this ALE thread, it is possible to use the user's ${HOME}/.ssh/rc file for this purpose. The manpage, in the SSHRC section, explicitly states that you should not write to stdout via this rc file, but the following script will work:

#!/bin/bash
if [ ! -t 1 ]; then
    # This is scp, sftp, a port forward, or something else
    exit
fi

# Use stderr like the manpage tells you to do
exec 1>&2

echo -e "This is output to stdout via the ${HOME}/.ssh/rc file.\n"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.