Giving Jenkins sudo privileges to write in Ubuntu involves adding the Jenkins user to the sudo group. Here's how you can do it using the usermod command:
Open a terminal on your Ubuntu machine.
- Add the Jenkins user to the sudo group:
sudo usermod -aG sudo jenkins
Explanation of the command:
- sudo: Run the command with superuser privileges.
- usermod: Modify user account properties.
- -aG sudo: Add the user to the "sudo" group.
- jenkins: The username of the Jenkins user.
You might also need to grant passwordless sudo access to the Jenkins user. To do this, edit the sudoers file:
- Add the following line to the file, replacing "jenkins" with the actual username if it's different:
jenkins ALL=(ALL) NOPASSWD:ALL
- This line allows the Jenkins user to execute all commands with sudo privileges without being prompted for a password.
- Save and exit the editor. In most terminal editors, you can press Ctrl + X, then Y, and finally Enter to save the changes.
Now the Jenkins user should have sudo privileges and be able to execute commands requiring elevated permissions. Keep in mind that granting passwordless sudo access should be done with caution and only for trusted users, as it could potentially introduce security risks.