What is Hola, Linux ๐ ?
Hola, Linux ๐ is a project that you can depend on it as a starter code for your brain ๐ง to rebuild Linux concepts.
Why this is possible?
There's a user that you need to disable his/her account and restrict from using a command-line.
Service Users.
First of all, lets grep information about all nologin users. if you didn't add users before to the nologin shell, the all users displayed are the service users.
mosalah@factory~$ grep nologin /etc/passwd
- Add new user and attach that user to the nologin shell.
Add new user "hashnoder" to nologin shell.
mosalah@factory~$ sudo useradd -s /sbin/nologin hashnoder
in the previous command i added new user, hashnoder and attached that user to nologin shell and now he can't start a command-line session.
If you want to switch an existing login user to restrict him/her from accessing the command-line utilities.
mosalah@factory~$ sudo usermod -s /sbin/nologin ex_hashnoder
in the previous command i modified an existing user, ex-hashnoder and attached that user to nologin shell, now he can't start a command-line session and he is restricted.
* You can display the hashnoder user and make sure he is attached to the nologin shell.
mosalah@factory~$ grep hashnoder /etc/passwd
you should see this entry.
Verfication Time.
Let's try to switch to the nologin user hashnoder through the CLI.
mosalah@factory~$ su - hashnoder
You should see a message
"This account is currently not available."
Customize nologin shell message.
- open the /etc/nologin.txt using your favorite editor.
mosalah@factory~$vi /etc/nologin.txt
-> Write your preferred message
Try again to switch to hashnoder user.
mosalah@factory~$ su - hashnoder
Your preferred message is shown instead of the default message.
To go back to your default (old) message, remove the /etc/nologin.txt file
mosalah@factory~$ sudo rm /etc/nologin.txt
Conclusion.
We created a new user and restrict that user from starting command-line sessions and he/she is no longer able to write command or login to the system.
We modified an exiting user from login shell to nologin shell.
We customized the default message that is displayed to the nologin user.