Question

how can disable a users access temporarily

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?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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:

  1. sudo passwd -u sammy

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

  1. 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` :)