To recover Jenkins credentials, follow one of these methods based on your setup:
-
Stop the Jenkins Service:
- Run the following command to stop Jenkins:
sudo systemctl stop jenkins
- Run the following command to stop Jenkins:
-
Edit the
config.xml
File:- Navigate to the Jenkins home directory (default is
/var/lib/jenkins
on Linux). - Open the
config.xml
file in a text editor:sudo nano /var/lib/jenkins/config.xml
- Navigate to the Jenkins home directory (default is
-
Disable Security Temporarily:
- Look for the
<useSecurity>
tag in theconfig.xml
file and set it tofalse
:<useSecurity>false</useSecurity>
- Save and close the file.
- Look for the
-
Restart Jenkins:
- Start Jenkins again:
sudo systemctl start jenkins
- Start Jenkins again:
-
Login Without Authentication:
- Open Jenkins in your browser; it should not require login.
- Navigate to Manage Jenkins > Configure Global Security and reset the admin password or add a new user.
-
Re-enable Security:
- Once you reset credentials, change
<useSecurity>
back totrue
inconfig.xml
and restart Jenkins to re-enable security.
- Once you reset credentials, change
If you have access to the Jenkins command line interface (CLI) and a known admin account exists:
- Open Jenkins CLI:
- Run the following command to reset a specific user’s password:
java -jar jenkins-cli.jar -s http://localhost:8080/ groovy = <<EOF import jenkins.model.* def instance = Jenkins.getInstance() def user = instance.getUser("admin") user.setPassword("new_password") user.save() EOF
- Run the following command to reset a specific user’s password:
Replace "admin"
with the username and "new_password"
with the desired new password.
-
Navigate to the Jenkins Script Console:
- Go to
http://<jenkins_url>/script
(requires login).
- Go to
-
Run Script to Reset Password:
- Run the following script in the console:
import hudson.security.HudsonPrivateSecurityRealm def user = Jenkins.instance.securityRealm.createAccount("admin", "new_password") user.save()
- Run the following script in the console:
This script resets the admin password to "new_password"
.
If you have a backup of Jenkins:
- Restore the backup files to the Jenkins home directory.
- Restart Jenkins to recover the previous credentials.
After following these methods, be sure to secure Jenkins again by re-enabling security and resetting passwords as needed.