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?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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` :)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.