linux安全之歷史命令追蹤

2021-09-02 20:21:53 字數 1846 閱讀 3882

修改配置檔案檢視任何登入主機的使用者在任何時間執行的任何命令

一 為history 命令新增日期時間顯示

[root@web44 ~]# vim /etc/bashrc

histtimeformat="%y-%m-%d:%h-%m-%s:`whoami`: "

export histtimeformat

//加入這兩行

二 腳步記錄所有使用者登陸伺服器上的所有操作命令

[root@web44 ~]# vim /etc/profile             //配置檔案最下方加入以下**

history

user=`whoami`

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

if [ "$user_ip" = "" ]; then

user_ip=`hostname`

fi if [ ! -d /var/log/history ]; then

mkdir /var/log/history

chmod 777 /var/log/history

fi if [ ! -d /var/log/history/$ ]; then

mkdir /var/log/history/$

chmod 300 /var/log/history/$

fi export histsize=4096

dt=`date +"%y%m%d_%h:%m:%s"`

export histfile="/var/log/history/$/$@$_$dt"

chmod 600 /var/log/history/$/*history* 2>/dev/null

三 過載使配置檔案立刻生效

[root@web44 ~]# source /etc/bashrc

[root@web44 ~]# source /etc/profile

四 檢視歷史命令記錄

[root@web44 ~]# history 

1 2018-12-08:10-34-15:root: systemctl set-default multi-user.target

2 2018-12-08:10-34-15:root: systemctl stop firewalld.service

3 2018-12-08:10-34-15:root: systemctl disable firewalld.service

4 2018-12-08:10-34-15:root: vim /etc/selinux/config

5 2018-12-08:10-34-15:root: grubby --update-kernel=all --args="console=ttys0"

6 2018-12-08:10-34-15:root: reboot

7 2018-12-08:10-34-15:root: nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.4.44/24 connection.autoconnect yes

8 2018-12-08:10-34-15:root: nmcli connection up eth0

9 2018-12-08:10-34-15:root: hostnamectl set-hostname web44

10 2018-12-08:10-34-15:root: exit

linux歷史命令

忘記歷史的linux使用者注定要輸入很多資訊。這也讓強有力的歷史命令 包括bash shell的歷史變體 不僅在援引之前執行命令而不需重新輸入它們時有用,在呼叫其它很少用到的命令時也有用,這省去了必須重新使用它們的麻煩。該命令按時間順序列出了之前執行命令的清單。該命令的輸出示例如下 01 histo...

linux之shell(3) 歷史命令

history 選項 歷史命令儲存檔案 c 清楚歷史命令 w 把快取之中的歷史命令寫入歷史命令儲存檔案 bash history 我們先來看看.bash history檔案 用cat bash history檢視一下內容 而用history命令來檢視 可以發現.bash history和用histo...

Linux學習之十二 命令別名與歷史命令

命令別名配置 alias,unalias 那麼需要下達 ls al more 這個命令,我是覺得很煩啦!要輸入好幾個單字!那可不可以使用 lm 來簡化呢?當然可以,你可以在命令列下面下達 root www alias lm ls al more 另外,命令別名的配置還可以取代既有的命令喔!舉例來說,...