How to disable a user's login without disabling the account under Linux-Unix

Let's say I create a user named "larry" using the adduser command. How can I make sure this user will not be able to login into the system directly, without disabling the account. In short, I want the account to be accessible via su - larry, but I do not want it to be accessible via a regular login prompt.

There are two methods to prevent a user from being able to login:
  1. you can lock the user by editing /etc/passwd
  2. by directly issuing the passwd command with the -l switch
Method #1
  1. open a terminal and login as root
  2. type vi /etc/passwd
Now you are in passwd file press i to edit the file.

Change the below line with the nologin option (/bin/bash means the user is able to login).


to this. nologin means the user is unable to login.
Method #2

To lock user: passwd -l username
To unlock user: passwd -u username

No comments:

Powered by Blogger.