C4f1151075b447779af31e99d6cf70e2c6eb47ac
By:
newbie

how can disable a users access temporarily

October 16, 2016 325 views
Nginx Ubuntu

how can i disable a user temporarily from server? i created this user for a developer access but now i dont need it for the moment. but i dont want to delete it permanently either. so what can i do?

1 Answer
xMudrii October 16, 2016
Accepted Answer

Hi @newbie,

I hope you want to disable user account on server for login.
You have two option to do it.
First option would be to lock account using passwd.

sudo passwd -l sammy

Executing this command will lock account.
When you try to SSH this will happen:

➜  ~ ssh sammy@ip
sammy@ip's password: 
Permission denied, please try again.

When you try su - sammy

➜  ~ su - sammy
Password: 
su: Authentication failure

When you need again your account you can unlock with:

  • sudo passwd -u sammy

Second option is to change login shell from /bin/bash to /bin/nologin
Open /etc/passwd with any text editor:

  • sudo nano /etc/passwd

Find out line that starts with username which you want to disable, e.g.:

sammy:x:1001:1001:,,,:/home/sammy:/bin/bash

Note the highlighted /bin/bash. Change it to /bin/nologin:

sammy:x:1001:1001:,,,:/home/sammy:/bin/nologin

When you try to SSH you will get:

➜  ~ ssh sammy@ip
sammy@ip's password: 
Permission denied, please try again.

When you try to su - sammy:

➜  ~ su - sammy
Password: 
Cannot execute /bin/nologin: No such file or directory

When you want to enable it again, just change /bin/nologin to /bin/bash` :)

Have another answer? Share your knowledge.