This tutorial post will help you with how to reset forgotten jenkins user password without disabling the security completely. Because, changing the security complete is not a good practice in production environment, this would make your jenkins environment secure less, so anybody can login without password.
You can use this disabling security method only when you have a situation like authentication completely not working for anyone to manage jenkins not for reseting a password of jenkins users.
If you are interested in learning, Request you to go through the below recommended tutorial.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
How to Reset Forgotten Jenkins Admin User's Password
Let's get started.
1. Generate hash password first for the user you wish to reset. Lets say i want to reset the password of admin user. You can follow the same procedure for any users.
Use "sha256sum" command to generate the hash password as below and make a note of the output that must be used while replacing the old password.
[root@jenkins-master ~]# echo -n 'redhat123{admin}' | sha256sum
b868ee6ad68d101ab46c8ee7569821917b4cd6375ad53ccd4d085a3e842a3bdd -
[root@jenkins-master ~]#
Where, "redhat123" is the new password and "admin" is the username. Replace these username and new password as per your user information.
2. Modify the user's config file to use the newly generated password.
While creating the user itself, config.xml file is generated for each user under the directory "/var/lib/jenkins/users/".
Go to the respective config file of the user "admin" and find the below line marked in yellow color.
Go to the respective config file of the user "admin" and find the below line marked in yellow color.
[root@jenkins-master ~]# cat /var/lib/jenkins/users/admin/config.xml
<?xml version='1.1' encoding='UTF-8'?>
<user>
<fullName>admin</fullName>
<properties>
<jenkins.security.ApiTokenProperty>
<tokenStore>
<tokenList/>
</tokenStore>
</jenkins.security.ApiTokenProperty>
<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>
<hudson.model.PaneStatusProperties>
<collapsed/>
</hudson.model.PaneStatusProperties>
<hudson.search.UserSearchProperty>
<insensitiveSearch>true</insensitiveSearch>
</hudson.search.UserSearchProperty>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>#jbcrypt:$2a$10$EODrFXhix9FkkZnp6ekaQOy1ZKNSfylV7GXjFJk3X76p43DgV2mT6</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<jenkins.security.LastGrantedAuthoritiesProperty>
<roles>
<string>authenticated</string>
</roles>
<timestamp>1533733962643</timestamp>
</jenkins.security.LastGrantedAuthoritiesProperty>
</properties>
[root@jenkins-master ~]#
Remove only the passwordhash line and replace with your username and new password in the format below.
<passwordHash>admin:b868ee6ad68d101ab46c8ee7569821917b4cd6375ad53ccd4d085a3e842a3bdd</passwordHash>
Finally, your config.xml file must be looks like,
[root@jenkins-master ~]# cat /var/lib/jenkins/users/admin/config.xml
<?xml version='1.1' encoding='UTF-8'?>
<user>
<fullName>admin</fullName>
<properties>
<jenkins.security.ApiTokenProperty>
<tokenStore>
<tokenList/>
</tokenStore>
</jenkins.security.ApiTokenProperty>
<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>
<hudson.model.PaneStatusProperties>
<collapsed/>
</hudson.model.PaneStatusProperties>
<hudson.search.UserSearchProperty>
<insensitiveSearch>true</insensitiveSearch>
</hudson.search.UserSearchProperty>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>admin:b868ee6ad68d101ab46c8ee7569821917b4cd6375ad53ccd4d085a3e842a3bdd</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<jenkins.security.LastGrantedAuthoritiesProperty>
<roles>
<string>authenticated</string>
</roles>
<timestamp>1533733962643</timestamp>
</jenkins.security.LastGrantedAuthoritiesProperty>
</properties>
[root@jenkins-master ~]#
Restart Jenkins Service to take the changes effect.
[root@jenkins-master ~]# systemctl restart jenkins
Now you would be able to login with new password. Hope you have got an idea how to reset forgotten jenkins user password. Going forward we will play more with jenkins integration tool.
Keep practicing and have fun. Leave your comments if any.
Stay connected with us on social networking sites, Thank you.
0 تعليقات