How To Reset Jenkins Password in Docker Containers in just 10 Simple Steps
If you forgot your admin password in Jenkins it’s possible to change it by modifying the config.xml
- Get into the docker Terminal
- Get the Jenkins Container Id.
docker ps
3. Run the command to jump Jenkins terminal with root user
docker exec -it — user=root <Container_Name or Container_Id> /bin/bash
4. Check for the var directory by doing ls command
5. Check for the jenkins_home directory
6. Now you have to navigate to the user in my case user is manas_7838
7. As you can see there is a config.xml file in the user manas_7838 now you have to modify the config file. and the config file looks like this:
<?xml version=’1.1' encoding=’UTF-8'?>
<user>
<version>10</version>
<id>manas</id>
<fullName>Manas Upadhyay</fullName>
<properties>
<com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin=”credentials@2.3.17">
<domainCredentialsMap class=”hudson.util.CopyOnWriteMap$Hash”/>
</com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty>
<hudson.plugins.emailext.watching.EmailExtWatchAction_-UserProperty plugin=”email-ext@2.82">
<triggers/>
</hudson.plugins.emailext.watching.EmailExtWatchAction_-UserProperty>
<hudson.model.MyViewsProperty>
<views>
<hudson.model.AllView>
<owner class=”hudson.model.MyViewsProperty” reference=”../../..”/>
<name>all</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class=”hudson.model.View$PropertyList”/>
</hudson.model.AllView>
</views>
</hudson.model.MyViewsProperty>
<org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty plugin=”display-url-api@2.3.4">
<providerId>default</providerId>
</org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty>
<hudson.model.PaneStatusProperties>
<collapsed/>
</hudson.model.PaneStatusProperties>
<jenkins.security.seed.UserSeedProperty>
<seed>152305d21909fb19</seed>
</jenkins.security.seed.UserSeedProperty>
<hudson.search.UserSearchProperty>
<insensitiveSearch>true</insensitiveSearch>
</hudson.search.UserSearchProperty>
<hudson.model.TimeZoneProperty/>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>#jbcrypt:$2a$10$8P5lZEaoWx8h4mn3Ap4eAe8cLYCFAK9ONwboiVjzHcU/KsIaqMbQS</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<hudson.tasks.Mailer_-UserProperty plugin=”mailer@1.34">
<emailAddress>abc@gmail.com</emailAddress>
</hudson.tasks.Mailer_-UserProperty>
<jenkins.security.ApiTokenProperty>
<tokenStore>
<tokenList/>
</tokenStore>
</jenkins.security.ApiTokenProperty>
<jenkins.security.LastGrantedAuthoritiesProperty>
<roles>
<string>authenticated</string>
</roles>
<timestamp>1618834831512</timestamp>
</jenkins.security.LastGrantedAuthoritiesProperty>
</properties>
</user>
8. Now you have to change the password by changing the passwordhash is define. As you can see, the password has been hashed using the BCrypt algorithm. So you have to bcrypted the password going to https://www.browserling.com/tools/bcrypt
9. Now you can edit the config.xml and you can replace this password with the new password
10. After complete editing the XML file you have to restart the Jenkins Server. Now you can log in with your new password
Thanks for Reading ☺️