本文目录导读:
在Ubuntu 18.04中,可以通过以下几种方法来实现账号锁定:
方法一:使用sudoers文件
1、打开终端,输入以下命令打开sudoers文件:
sudo visudo
2、在打开的文件中,找到以下行:
Allow root to run any commands anywhere
root ALL=(ALL:ALL) ALL
3、在该行的下方添加以下内容
username ALL=NOPASSWD:ALL
username是要锁定的账号的用户名。
4、保存并关闭文件。
5、在终端中输入以下命令,以锁定该账号:
sudo passwd -l username
此时,系统会提示输入当前用户的密码,输入密码后即可锁定该账号。
方法二:使用lightdm
1、打开终端,输入以下命令以编辑lightdm的配置文件:
sudo nano /etc/lightdm/lightdm.conf
2、在打开的文件中,找到以下行:
#greeter-hide-users=true
将其修改为
greeter-hide-users=true
3、保存并关闭文件。
4、重新启动系统,即可实现账号锁定,此时,除了管理员账号外,其他账号都无法登录系统。
方法三:使用ufw和iptables
1、打开终端,输入以下命令以安装ufw和iptables:
sudo apt-get update && sudo apt-get install ufw iptables
2、输入以下命令以配置ufw
sudo ufw enable input deny incoming deny outgoing deny enable logging on; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes > /dev/null; done > /etc/iptables/rules.v4; sudo iptables-save > /etc/iptables/rules.v4; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes > /etc/iptables/rules.v6; done > /etc/iptables/rules.v6; sudo iptables-save > /etc/iptables/rules.v6; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes >> /etc/iptables/rules-save; done >> /etc/iptables/rules-save; sudo iptables-save >> /etc/iptables/rules-save; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes >> /etc/iptables/rules-save-v6; done >> /etc/iptables/rules-save-v6; sudo iptables-save >> /etc/iptables/rules-save-v6; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes >> /etc/iptables/rules-custom; done >> /etc/iptables/rules-custom; sudo iptables-save >> /etc/iptables/rules-custom; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest $Allowed/Blocked $Bytes >> /etc/iptables/rules-custom-v6; done >> /etc/iptables/rules-custom-v6; sudo iptables-save >> /etc/iptables/rules-custom-v6; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allowed/Blocked Bytes Drop; do echo $Chain $Target $Prot $Src $Dest Allowed Bytes >> /var/log/ufw.log; done > /var/log/ufw.log; sudo iptables -L INPUT -v -n | while read Chain Target Prot Src Dest Allow
最后修改时间:
文章相关标签:
如何在Linux中清空挂载点(mnt)
上一篇
2023年12月12日 15:14
云游戏服务器:实现游戏体验的强大后盾
下一篇
2023年12月12日 15:27
评论已关闭