Score:0

How to disable some commands on root user?

fr flag

Some commands like npm, composer, git, etc are not recommended run as root user. But sometimes I forget to run it when I log in as root, and my coworkers also sometimes do that too. That makes some files/dirs unable to be accessed by non-root users, which sometimes makes our website/apps errors. Is there any way to disable those commands when run as a root user? at least give warning/confirmation before running those commands.

user535733 avatar
cn flag
Fix whatever problem with your systems or workflow that requires you and your co-workers to use (abuse) root so frequently.
fr flag
@user535733 thanks for your advice, but actually I am a very rare abused root user. And I can change my workflow, but I don't have a power to change my co-worker workflow.
Score:4
ng flag

Ubuntu does not have a root user so I am assuming that you are using sudo su.

There are very few situations where this is needed. It's better that you learn to use sudo effectively only when superuser access is actually needed.

When you are using sudo su, everything you run is as if you were using the root user. By definition, the root user can do anything they want. You cannot restrict what can be done by sudoers when using sudo.

You cannot restrict the root user, nor can you restrict what someone with sudo privileges can do when using sudo, so what you are asking is impossible.

The better option is to correct your workflow so that you are not overusing sudo when it is not necessary.

Score:3
cn flag

You can use aliases to prevent those commands from execution. for example for preventing command git from execution you can append this line to the file /root/.bashrc:

alias git='echo You are root!'
fr flag
Thanks. That's what I'm looking for
muru avatar
us flag
@MuhammadDyasYaskur just a note that this won't apply if you do `sudo git`.
fr flag
@muru yeah, I also tried it, and no problem, I and my co-workers never use `sudo` on commands that I mentioned. I just want to prevent the commands from `sudo su` or root user login.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.