重新编译bash源码 
1.打开config-top.h文件,把#define SYSLOG_HISTORY这个宏定义打开。
2.修改bashhist.c文件,添加一个sshd来源IP记录


 
   
  1. void bash_syslog_history (line)  
  2. const char *line;  
  3. {  
  4. char trunc[SYSLOG_MAXLEN];  
  5. char ip[16] ={0}; 
  6. char * tmpstr = getenv("SSH_CLIENT"); 
  7. int nlength = 0
  8. while(tmpstr != NULL)  
  9.   if(tmpstr[nlength++] == ' ') 
  10.   { 
  11.        break; 
  12.   } 
  13.   if(nlength > 16) 
  14.    { 
  15.        strncpy(ip,"get env error!",sizeof("get env error!")); 
  16.        break; 
  17.    } 
  18. if(nlength>0 && nlength <=16) 
  19.   strncpy(ip,tmpstr,nlength); 
  20.  
  21. if (strlen(line) <</span> SYSLOG_MAXLEN)  
  22.     syslog(SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: IP=%s PID=%d PPID=%d SID=%d User=%s CMD=%s",ip, getpid(), getppid(), getsid(getpid()), cu rrent_user.user_name, line);  
  23. else  
  24.   {  
  25.    strncpy (trunc, line, SYSLOG_MAXLEN);  
  26.    trunc[SYSLOG_MAXLEN - 1] = '';  
  27.    syslog(SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): IP=%s PID=%d PPID=%d SID=%d User=%s CMD=%s",ip, getpid(), getppid(), getsid( getpid()), current_user.user_name, trunc);  
  28.   }