linux系統記錄使用者操作實現方法

2021-07-30 22:08:47 字數 977 閱讀 4652



linux系統記錄使用者操作實現方法

針對登陸系統的不同使用者,記錄其相關操作,並生成檔案。

實現方法,修改/etc/profile檔案,加入如下資訊:

# 設定儲存歷史命令的檔案大小

export histfilesize=10000000

# 儲存歷史命令條數

export histsize=1000000

# 實時記錄歷史命令

export prompt_command="history -a"

# 記錄每條歷史命令的執行時間

export histtimeformat="%y-%m-%d-%h:%m:%s "

history

user_ip=`who -u am i 2>/dev/null| awk ''|sed -e 's/[()]//g'`

if [ "$user_ip" = "" ]

then

user_ip=`hostname`

fiif [ ! -d /tmp/history ]

then

mkdir /tmp/history

chmod 777 /tmp/history

fiif [ ! -d /tmp/history/$ ]

then

mkdir /tmp/history/$

chmod 300 /tmp/history/$

fidt=`date +"%y%m%d-%h%m%s"`

export histfile="/tmp/history/$/$-history-$dt"

chmod 600 /tmp/history/$/*history* 2>/dev/null

儲存後,執行source /etc/profile命令即可,生成的記錄檔案位置在/tmp/history下,每個使用者名稱生成乙個目錄。

注:必須是普通使用者登陸等操作才會記錄,從root使用者su切到普通使用者的操作不會記錄。

記錄使用者操作

在最近工作中,博主手頭上的web專案提了乙個新的需求,這個需求大體上就是希望系統能夠記錄使用者做了哪些操作,包括這些操作的細節。大家都知道,使用者的操作無非就是增,刪,改,查。因為我現在做的這個專案對使用者的查詢操作不敏感,所以只需記錄增,刪,改。在做之前呢,我的leader給了我乙個建議 你要不寫...

audit plugin 記錄使用者操作資訊

mysql5.5的audit審計功能是被自動觸發的,在檔案plugin audit.h中可以看到比較詳細的定義 在audit外掛程式中,可控制的變數包括thd以及事件 其中事件分為兩種結構體,可以進行強制轉換 第一種 48 struct mysql event general 49 觸發條件 def...

Linux記錄使用者執行命令

bin bash by lumia98 vip.qq.com 記錄使用者執行命令及ip位址 登入提示許可權不足可以忽略,因為這是禁止使用者刪除許可權提示 linux詳細記錄每個使用者的執行命令 缺陷不能記錄vim裡的命令 檔案存放在 etc profile.d 或者 etc profile sour...