How do I restrict certain commands to only run with sudo?

0
8
Asked By CuriousCat123 On

I mistakenly ran the poweroff command while trying to execute another command from my command history. I want to ensure that specific commands can only be executed with sudo access to prevent unauthorized users from running them. How can I set this up? Also, I'm particularly concerned about preventing unauthorized users from using the poweroff command.

5 Answers

Answered By TechieWizard99 On

On most modern systems that use systemd, the 'poweroff' command is just a shortcut for a systemctl command. User permissions for power controls are managed via polkit, meaning that local users can generally access power controls. However, if someone connects through SSH, they'll need sudo to execute these commands. So, be cautious about your permissions!

SkepticalSteve -

Yeah, if an unauthorized user could just execute poweroff, all your unsaved work would be gone. It's a good reminder to edit your question or think through permissions.

Answered By SysAdminGuru On

You should double-check your sudoers configuration to ensure commands aren't running without a password. Having elevated permissions for shutdown commands is essential for security.

NervousNelly -

Got it, thanks! I'll make sure to check that out.

Answered By HelpfulHank On

To prevent non-privileged users from executing shutdown commands, you'll need to modify your user permissions. Make sure that only the root user can run critical commands like poweroff or shutdown. You might need to pause and review your current setup to avoid any security loopholes.

Answered By CommandMaster22 On

Also, remember to always research commands before running them! Familiar commands like 'sudo apt update' or 'sudo apt upgrade' are great examples of those that need elevated permissions. Just stay informed about what they do to prevent mishaps!

Answered By CodeWizard42 On

If you want to restrict certain commands to run only as root, you can find the executable in /usr/bin. Make sure it's owned by root with `chown root:root ` and then limit its permissions to just the owner with `chmod 744 `. But beware, modifying executables in /usr could be undone by package manager updates, so tread lightly!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.