A2oz

How to Recover Jenkins Password in Linux?

Published in Jenkins 3 mins read

You cannot directly recover a forgotten Jenkins password in Linux. Jenkins stores passwords in a secure and encrypted format, meaning even the administrator cannot access them directly.

Here's how you can regain access to your Jenkins instance:

1. Reset the Password Through the Jenkins Interface

  • If you have administrative access:
    • Log in to your Jenkins instance as an administrator.
    • Navigate to Manage Jenkins > Manage Users.
    • Select the user whose password you want to reset.
    • Click Reset Password.
    • Jenkins will send a new password to the user's email address.
  • If you do not have administrative access:
    • You may need to contact your system administrator to reset the password.

2. Reset the Password by Modifying the config.xml File

  • Important: This method should be used with caution, as it involves modifying core Jenkins configuration files.
  • Backup: Before making any changes, always create a backup of your config.xml file.
  • Locate the config.xml file: The file is typically located in /var/lib/jenkins/config.xml.
  • Edit the file: Open the config.xml file using a text editor like nano or vim.
  • Find the user's entry: Search for the <user> tag corresponding to the user whose password you want to reset.
  • Modify the passwordHash attribute: Replace the existing passwordHash value with the desired new password.
  • Save the changes: Save the config.xml file.
  • Restart Jenkins: Restart the Jenkins service to apply the changes.

Note: This method involves manually setting a new password. Remember to change the password to a strong and secure one after logging in.

3. Reset the Password Using the Jenkins CLI

  • Install the Jenkins CLI: Follow the instructions on the Jenkins documentation to install the Jenkins CLI.
  • Use the jenkins-cli command: Execute the following command to reset the password for a specific user:
    jenkins-cli.jar -s http://<jenkins_url>  -auth <username>:<api_token>  user set <username> -password <new_password>

    Replace:

  • <jenkins_url> with your Jenkins server URL.
  • <username> with the username of the user whose password you want to reset.
  • <api_token> with your API token.
  • <new_password> with the new password you want to set.

Important: Always ensure you are using a secure connection when accessing the Jenkins CLI.

By following these steps, you can recover your Jenkins password and regain access to your Jenkins instance.

Related Articles