A Linux system administrator needs to know some Linux tricks. In this article, you will learn how to disable shutdown and reboot commands in Linux.
To power down a Linux system, you need to use the shutdown command schedules a time. While Linux distros such as Ubuntu, Linux Mint, Mandriva, make it possible to reboot/halt/shutdown the system as a normal user, by default. It is not an ideal setting, especially on servers. Above all, it must be something to worry about especially for a system administrator.
To fix this issue, we will show how to disable shutdown and reboot commands for normal users in Linux.
How to disable shutdown and reboot commands in Linux
Let’s review one of the easiest ways of shutdown and reboot commands using the /etc/sudoers file.
Add these lines to the Command Aliases section.
Cmnd_Alias SHUTDOWN = /sbin/shutdown,/sbin/reboot,/sbin/halt,/sbin/poweroff User privilege specification eldernode ALL=(ALL:ALL) ALL, !SHUTDOWN Allow members of group sudo to execute any command %developers ALL=(ALL:ALL) ALL, !SHUTDOWN
Try to execute shutdown and reboot commands as a normal user.
chmod o-x /sbin/shutdown chmod o-x /sbin/reboot
Please Note: Under systemd, these file(/sbin/shutdown, /sbin/reboot, /sbin/halt, /sbin/poweroff) are only symbolic links to /bin/systemctl:
ls -l /sbin/shutdown ls -l /sbin/reboot ls -l /sbin/halt ls -l /sbin/poweroff
In conclusion, you can remove execution permissions as explained above, to prevent other users from running these commands. Since is not effective under systems. , you can remove execution permissions on /bin/systemctl meaning all other users except root will only run systemctl.
chmod o-x /bin/systemctl
Good job! You finished the tutorial and reached to the purpose of our guide. Share with us if you know any other way of doing this, in the comments.
Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problems in it.
You can find more related articles in: