linux 終端開啟自動登出

來源:互聯網
上載者:User

標籤:

當使用root使用者登入至終端後 不及時登出,那麼會話會一直存在,這樣有很大的安全隱患。為了將風險降至最低,接下來將介紹如何配置自動鎖定或登出。

1. 安裝screen
yum install -y screen
2. 使用root使用者在 /etc/profile 添加以下內容,確保本檔案的進程不會被中斷。
trap "" 1 2 3 15
3. 接下來在 /etc/profile 中添加以下內容,為每個登入使用者建立虛擬終端。
SCREENEXEC="screen"if [ -w $(tty) ]; thentrap "exec $SCREENEXEC" 1 2 3 15echo -n ‘Starting session in 10 seconds‘sleep 10exec $SCREENEXECfi

現在每個使用者登入後都會有個提示資訊"Starting session in 10 seconds", 會在10s後建立終端,這個提示資訊和建立終端的時間你可以自訂,只需要變更提示資訊及 sleep 後面的數字即可。

4. 配置screen

    自動登出

    在/etc/screenrc  中添加

idle 120 quitautodetach off

   會話閑置120s 後會自動結束, 更改閑置時間 只需更改 idle 後面的數字即可

   自動鎖定

   在/etc/screenrc  中添加

idle 120 lockscreenautodetach off

  會話閑置120s 後會自動鎖定, 更改閑置時間 只需更改 idle 後面的數字即可


此配置只會影響新登入的使用者。


參考: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/pdf/Security_Guide/Red_Hat_Enterprise_Linux-6-Security_Guide-en-US.pdf 

linux 終端開啟自動登出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.