How to Disable User Login in Linux
To prevent a user from logging in, you can achieve this by modifying the user’s shell. Here are the specific steps:
- Open the terminal and use the following command to check the user’s shell:
cat /etc/passwd | grep 用户名
The username is the username of the user who needs to be banned from logging in.
- Change the user’s shell to nologin using the following command:
sudo usermod -s /usr/sbin/nologin 用户名
- Confirm that the user’s shell has been changed to nologin.
cat /etc/passwd | grep 用户名
The user is now prohibited from logging into the system. If you need to allow the user to log in again, you can use the following command to change their shell back to the default value:
sudo usermod -s /bin/bash 用户名