Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
public:ssh [2011/12/13 21:53] – [SOCKS proxies] Nicopublic:ssh [2013/11/17 22:26] Nico
Line 55: Line 55:
   * surf   * surf
  
 +====== Run a command on login ======
 +
 +Commands in /etc/ssh/sshrc are executed by ssh when the user logs in, just before the user's shell (or command) is started. It's commonly used to send alerts using mail:
 +
 +<code>
 +#!/bin/sh
 +# source: http://blog.uggy.org/post/2009/06/05/Execution-de-commande-lors-d-une-connexion-SSH
 +DATE=`date "+%d.%m.%Y--%Hh%Mm"`
 +IP=`echo $SSH_CONNECTION | awk '{print $1}'`
 +REVERSE=`dig -x $IP +short`
 +HOSTNAME=`hostname`
 +
 +echo "Connexion de $USER sur $HOSTNAME
 +IP: $IP
 +ReverseDNS: $REVERSE
 +Date: $DATE
 +
 +" | mail -s "Connexion de $USER sur $HOSTNAME" me@mail.com
 +</code>