Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 系統操作痕跡清理:歷史指令與近期文件記錄一鍵清除

編輯:Linux 教學

風險來源:雙重記錄機制洩露操作軌跡

Linux 兩大機制預設記錄用戶行為:

  1. Shell 歷史指令:終端/文字模式下上下鍵調用歷史,儲於 ~/.bash_history
  2. 圖形介面近期文件:GNOME 面板「開啟最近文檔」列表,儲於 ~/.recently-used

同帳號登入者可完整查看操作軌跡,構成隱私與安全風險。

解決方案:開機自動清空雙記錄文件

原理:兩文件均為用戶家目錄下隱藏文本文件,清空即斷開記錄鏈。以常用 root 登入為例(雖不建議),編輯 /etc/rc.d/rc.local 加入:

> /root/.bash_history
> /root/.recently-used

重定向空輸出至文件即實現截斷清空。每次開機自動執行,確保歷史不留痕。

進階建議

  • 非 root 用戶:將命令加入對應用戶 ~/.bash_logout 登出時清理,或 cron 定時任務
  • 選擇性保留:若需保留部份歷史,可用 history -d 刪除特定行號,或 HISTIGNORE 變數過濾敏感指令
  • 圖形介面深度清理:GNOME/KDE 尚有 ~/.local/share/recently-used.xbel、~/.recently-used.xbel 等新版路徑,建議同步清理
  • 審計合規場景:若系統需留存操作審計軌跡,請勿啟用此清理,改用集中式日誌審計系統

一鍵手動清理腳本範例

#!/bin/bash
# clean_traces.sh
USER_HOME=$(eval echo ~$USER)
> "$USER_HOME/.bash_history"
> "$USER_HOME/.recently-used"
> "$USER_HOME/.local/share/recently-used.xbel" 2>/dev/null
> "$USER_HOME/.recently-used.xbel" 2>/dev/null
echo "用戶 $USER 操作痕跡已清理"

賦予執行權限後隨時可手動或排程執行。

Copyright © Windows教程網 All Rights Reserved