How can CentOS prevent user login?
You can disable CentOS user login by following these steps:
- Login to the CentOS system as the root user.
- Open the terminal window and enter the following command to edit the “/etc/passwd” file:
- Open the /etc/passwd file using sudo and the vi text editor.
- Locate the line of the user you want to disable login for in the open file. Each user’s line should begin with their username, with the username and other information separated by a colon “:”.
- Change the login shell field in the user profile to “/sbin/nologin” or “/usr/sbin/nologin”. This will prevent the user from logging into the system using a shell.
- username:x:1000:1000:Username:/home/username:/sbin/nologin – This line contains the information for the user with the username “username”, including their user ID and home directory.
- Save the file and exit the editor.
- Users who are prohibited from logging in will not be able to access the system through SSH, telnet, or any other login methods.
Please note that if you disable the root user login, you will not be able to use the root user for logging in. Make sure you have another user with administrator privileges or a way to access the system.