限时登录Linux的实现

一个简单的限时登录方法:写三个 shell 程序,调用 at 和系统维护功能:
1. 在指定的时间执行该shell,在/etc下生成一名为nologin的文件,如:
vi /sbin/login.denied
echo " Login Denied " > /etc/nologin
chmod 700 login.denied
2. 在指定的时间执行该shell,删除/etc/下的nologin文件,如:
vi /sbin/login.allowed
if [ -f /etc/nologin ]; then
rm /etc/nologin
fi
chmod 700 login.allowed
3. 编写一个限制时间的shell,如:
vi /sbin/security
if [ -f /sbin/login.denied ]; then
at -f /sbin/login.denid 22:00
fi
if [ -f /sbin/login.allowed ]; then
at -f /sbin/login.allowed 8:00
if
此种设置的功能是:从晚上10:00 到第二天早上 8:00 禁止非 root 用户登录,显示为系统维护状态。
另外,还需对 root 用户的登录终端进行限制,最好设置在 console,在 RedHat 5.0 下在 /etc/security/access.conf
中配置
-:root:ALL EXCEPT console
就可以了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/51fda7a93d482f121b03b598eb443fb5.html