If you have forgotten the Jenkins admin password and can’t log in to a Jenkins user interface (UI) as administrator, you can connect to a Jenkins server via SSH and reset the Jenkins admin password.
The simplest solution is to completely disable security in /var/lib/jenkins/config.xml
file, access the Jenkins UI omitting authentication and rest the Jenkins admin password.
Cool Tip: Jenkins Username & Password by Default! Read more →
Reset Jenkins Admin Password
Make a backup copy of a Jenkins config file (this step is important as after resetting the Jenkins admin password we would need to restore the previous settings):
$ cp /var/lib/jenkins/config.xml /var/lib/jenkins/config.xml.back
Open the config file /var/lib/jenkins/config.xml
and disable the security:
<useSecurity>false</useSecurity>
Restart the Jenkins service:
$ systemctl restart jenkins
Go to the Jenkins UI (you won’t be asked for any credentials this time) and reset the admin password:
- Navigate to
"Manage Jenkins"
->"Security"
->"Configure Global Security"
->"Authentication"
- Select the
"Security Realm"
(e.g."Jenkins’ own user database"
) and click on"Save"
- Go to
"People"
-> Click on a username for which you want to change the password (e.g.admin
) ->"Configure"
-> Enter a new password in the"Password"
and"Confirm password"
fields and click on"Save"
Once the admin password is reset, restore the previous /var/lib/jenkins/config.xml
file and restart Jenkins:
$ mv /var/lib/jenkins/config.xml.back /var/lib/jenkins/config.xml $ systemctl restart jenkins
thanks a lot !!
It worked!!! Thanks.
This appears to no longer work. After setting to false Jenkins will no longer start.
First stop the Jenkins from the services and then set the to false and then restart the Jenkins service. It should work.
Hi AVATAR42
It worked for me in Jenkins 2.319.1
Thanks to “admin”
Thanks. This worked for me on Jenkins v2.346 !