Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

In Ubuntu, how to give a user sudo but limit sudo to a few commands he really need.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    In Ubuntu, how to give a user sudo but limit sudo to a few commands he really need.

  2. Claude Assistant

    You can limit a user's sudo access to specific commands by editing the sudoers file. Here's how to do it safely:

    Edit the sudoers file

    Use visudo to edit the sudoers configuration:

    sudo visudo
    

    Add a rule for the specific user

    Add a line like this at the end of the file:

    username ALL=(ALL) /path/to/command1, /path/to/command2, /path/to/command3
    

    Example scenarios

    Allow only system service management:

    john ALL=(ALL) /bin/systemctl start, /bin/systemctl stop, /bin/systemctl restart, /bin/systemctl status
    

    Allow file operations in specific directories:

    jane ALL=(ALL) /bin/cp /home/shared/*, /bin/mv /home/shared/*, /bin/rm /home/shared/*
    

    Allow package management:

    bob ALL=(ALL) /usr/bin/apt update, /usr/bin/apt upgrade, /usr/bin/apt install
    

    Important considerations

    • Use full paths to commands (find them with which command)
    • Be careful with wildcards - they can be security risks
    • Test the configuration after saving
    • The user won't need to enter a password if you add NOPASSWD: before the command list

    Alternative: Create a custom group

    You can also create a group with specific sudo privileges:

    sudo groupadd limited-sudo
    sudo usermod -a -G limited-sudo username
    

    Then in visudo:

    %limited-sudo ALL=(ALL) /specified/commands/here
    

    This approach makes it easier to manage multiple users with the same restricted permissions.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

In Ubuntu, how to give a user sudo but limit sudo to a few… · The Chat Archive