How can Linux be configured to prevent users from loggi…
To prevent Linux users from logging in, follow these steps:
- Log in to the Linux system as the root user.
- Open the terminal window and enter the following command to edit the /etc/passwd file:
- Open the file /etc/passwd using the program vi with superuser privileges.
- In the open /etc/passwd file, locate the line of the user to be denied login. Each user’s line begins with the username and is separated by colons (:) into different fields.
- Add a special shell after the username to indicate that the user cannot log in. For example, modify the line to:
- Username:x:1000:1000:User Name:/home/username:/usr/sbin/nologin
- The username is the username that is to be banned from logging in.
- Save the file and close the editor.
- After completing the above steps, the user will be unable to log into the system via SSH, terminal, or any other means.
Please note that modifying the /etc/passwd file can be risky. If you are not familiar with the Linux system, please proceed with caution. Additionally, users who are not allowed to log in can still run tasks or processes that were previously set up. If you want to completely disable a user, consider deleting or disabling that user.