visudo

Here's an example of how you can use visudo to grant permissions to a user:

  1. Open a terminal window.

  2. Type the following command and press Enter to open the sudoers file with visudo:

    sudo visudo

    This will prompt you to enter your password.

  3. Once the sudoers file opens in the text editor, navigate to the section that defines user privileges. It typically starts with a line similar to:

    # User privilege specification
  4. To grant permissions to a specific user, add a line in the following format:

    username    ALL=(ALL:ALL) command

    Replace username with the actual username of the user you want to grant permissions to, and replace command with the specific command or commands they should be able to execute with sudo.

    For example, let's say you want to grant the user "john" the ability to manage network settings using the ifconfig command. You would add the following line:

    john    ALL=(ALL:ALL) /sbin/ifconfig

    This grants the user "john" the ability to run the ifconfig command with sudo.

  5. Save the changes and exit the text editor. In vi, you can press Esc to exit insert mode, then type :wq and press Enter.

    Visudo will perform a syntax check, and if everything is valid, it will save the changes to the sudoers file.

Now, the user "john" should be able to execute the specified command with elevated privileges using the sudo command.

Grant ALL permissions to User

If you want to grant permission for a user to run any command with sudo, you can use the wildcard character ALL. Here's an example:

  1. Open a terminal window.

  2. Type the following command and press Enter to open the sudoers file with visudo:

    sudo visudo

    This will prompt you to enter your password.

  3. Once the sudoers file opens in the text editor, navigate to the section that defines user privileges. It typically starts with a line similar to:

    # User privilege specification
  4. To grant permission for a specific user to run any command with sudo, add a line in the following format:

    username    ALL=(ALL:ALL) ALL

    Replace username with the actual username of the user you want to grant permissions to.

    For example, if you want to grant the user "john" permission to run any command with sudo, you would add the following line:

    john    ALL=(ALL:ALL) ALL
  5. Save the changes and exit the text editor. In vi, you can press Esc to exit insert mode, then type :wq and press Enter.

    Visudo will perform a syntax check, and if everything is valid, it will save the changes to the sudoers file.

Now, the user "john" should have full sudo privileges and be able to execute any command with elevated privileges using the sudo command.

Last updated