国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

通過登陸IP記錄Linux所有用戶登錄所操作日志的方法

2020-06-13 12:22:34
字體:
供稿:網(wǎng)友
對于Linux用戶操作記錄一般通過命令history來查看歷史記錄,但是如果在由于誤操作而刪除了重要的數(shù)據(jù)的情況下,history命令就不會有什么作用了。那么依然要存有歷史操作記錄應該如何來實現(xiàn)呢
 
 
對于Linux用戶操作記錄一般通過命令history來查看歷史記錄,但是如果在由于誤操作而刪除了重要的數(shù)據(jù)的情況下,history命令就不會有什么作用了。那么依然要存有歷史操作記錄應該如何來實現(xiàn)呢? 

其實我們可以通過登陸IP地址來記錄所有用戶登錄所操作的歷史操作!具體操作就是在/etc/profile配置文件的末尾加入以下腳本代碼來實現(xiàn): 

復制代碼
代碼如下:

[root@server ~]# cat >>/etc/profile<< EOF 

> history 

> USER=`whoami` 

> USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` 

> if [ "$USER_IP" = "" ]; then 
> USER_IP=`hostname` 
> fi 

> if [ ! -d /tmp/history ]; then 
> mkdir /tmp/history 
> chmod 777 /tmp/history 
> fi 

> if [ ! -d /tmp/history/${LOGNAME} ]; then 
> mkdir /tmp/history/${LOGNAME} 
> chmod 300 /tmp/history/${LOGNAME} 
> fi 

> export HISTSIZE=4096 

> DT=`date +"%Y-%m-%d_%H:%M:%S"` 

> export HISTFILE="/tmp/history/${LOGNAME}/${USER}@${USER_IP}_history.$DT" 

> chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null 

> EOF 
[root@server ~]# source /etc/profile 
[root@server ~]# logout 
# 此時需要退出系統(tǒng)再重新登錄,在/tmp/history/目錄下才有記錄 

通過上面的腳本代碼可以看出來,在系統(tǒng)的/tmp下就新建了個history目錄(這個目錄可以自定義),在目錄中記錄了所有的登陸過系統(tǒng)的用戶和IP地址,這也是監(jiān)測系統(tǒng)安全的方法之一。在進行一系列的操作之后,我們進入/tmp/history目錄查看歷史記錄: 

復制代碼
代碼如下:

[root@server ~]# cd /tmp 
[root@server tmp]# ll 
總計 24 
drwx------ 2 root root 4096 2012-10-11 gconfd-root 
drwxrwxrwx 3 root root 4096 2012-10-11 history 
drwx------ 2 root root 4096 08-11 01:11 keyring-Ki8IOJ 
srwxr-xr-x 1 root root 0 2012-10-11 mapping-root 
srw------- 1 root root 0 2012-10-11 scim-panel-socket:0-root 
drwx------ 2 root root 4096 2012-10-11 ssh-jPPigl3182 
drwx------ 2 root root 4096 10-10 21:16 ssh-KDmPtr3350 
[root@server tmp]# cd history/ 
[root@server history]# ll 
總計 4 
d-wx------ 2 root root 4096 10-10 21:16 root 
[root@server history]# cd root/ 
[root@server root]# ll 
總計 4 
-rw------- 1 root root 37 10-10 21:16 root@192.168.1.96_history.2012-10-10_21:16:42 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汝城县| 海阳市| 那曲县| 巢湖市| 始兴县| 来安县| 辽阳县| 伊吾县| 利辛县| 尉氏县| 蓝山县| 芜湖市| 南京市| 剑阁县| 湖北省| 崇信县| 石泉县| 西乌| 拜城县| 平湖市| 平利县| 固阳县| 江孜县| 库尔勒市| 神农架林区| 康定县| 内丘县| 天津市| 苏州市| 白城市| 平谷区| 铜梁县| 衡东县| 历史| 洪江市| 调兵山市| 天津市| 张家港市| 宜章县| 临清市| 临湘市|