■ 環境

  • Linux

■ man


$ man ssh
             Commands in this file are executed by ssh when the user logs in, just before the user's
             shell (or command) is started.  See the sshd(8) manual page for more information.
$ man 8 sshd
     If the file ~/.ssh/rc exists, sh(1) runs it after reading the environment files but before
     starting the user's shell or command.  It must not produce any output on stdout; stderr must be
     used instead.  If X11 forwarding is in use, it will receive the "proto cookie" pair in its stan‐
     dard input (and DISPLAY in its environment).  The script must call xauth(1) because sshd will
     not run xauth automatically to add X11 cookies.

     The primary purpose of this file is to run any initialization routines which may be needed
     before the user's home directory becomes accessible; AFS is a particular example of such an

     This file will probably contain some initialization code followed by something similar to:

        if read proto cookie && [ -n "$DISPLAY" ]; then
                if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then
                        # X11UseLocalhost=yes
                        echo add unix:`echo $DISPLAY |
                            cut -c11-` $proto $cookie
                        # X11UseLocalhost=no
                        echo add $DISPLAY $proto $cookie
                fi | xauth -q -

     If this file does not exist, /etc/ssh/sshrc is run, and if that does not exist either, xauth is
     used to add the cookie.

■ 実験


echo "[`date '+%Y/%m/%d %H:%M:%S'`] $USER $SSH_CLIENT" >> /tmp/login


$ vagrant ssh
Last login: Fri Oct 23 19:10:15 2015 from
[vagrant@localhost ~]$ cat /tmp/login.lst
[2015/10/23 19:10:15] vagrant 60993 22
[2015/10/23 19:11:28] vagrant 60998 22
[vagrant@localhost ~]$