jenkins安装完成后,会生成一个默认初始密码并保存在文件中
cat /data/jenkins/jenkins_data/secrets/initialAdminPassword
/data/jenkins/jenkins_data是你JENKINS_HOME数据目录,记得替换成自己实际目录。
那么如果jenkins密码忘记了,该怎么办呢?别慌,咱也有办法处理这种情况,请继续看以下内容:
admin用户信息默认存放在/data/jenkins/jenkins_data/users/admin_4839668626550902140/config.xml文件中。
[root@localhost admin_4839668626550902140]# cat config.xml
<?xml version='1.1' encoding='UTF-8'?>
<user>
<version>10</version>
<id>admin</id>
<fullName>admin</fullName>
<description></description>
<properties>
<io.jenkins.plugins.DingTalkUserProperty plugin="dingding-notifications@2.7.1">
<mobile></mobile>
</io.jenkins.plugins.DingTalkUserProperty>
<jenkins.security.ApiTokenProperty>
<tokenStore>
<tokenList>
<jenkins.security.apitoken.ApiTokenStore_-HashedToken>
<uuid>a366415a-e4ca-42fc-a16b-c2a629bdf266</uuid>
<name>Token created on 2024-06-05T10:05:18.463078+08:00</name>
<creationDate>2024-06-05 02:05:18.465 UTC</creationDate>
<value>
<version>11</version>
<hash>c2954b9618772d38751a7121904591dcc5ac11d1f1a8c08b0124b7010a018d51</hash>
</value>
</jenkins.security.apitoken.ApiTokenStore_-HashedToken>
</tokenList>
</tokenStore>
</jenkins.security.ApiTokenProperty>
<io.jenkins.plugins.localization__zh__cn.UserCommunityProperty plugin="localization-zh-cn@1.0.24">
<showCondition>Chinese</showCondition>
</io.jenkins.plugins.localization__zh__cn.UserCommunityProperty>
<jenkins.console.ConsoleUrlProviderUserProperty/>
<com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin="credentials@1311.vcf0a_900b_37c2">
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
<entry>
<com.cloudbees.plugins.credentials.domains.Domain>
<specifications/>
</com.cloudbees.plugins.credentials.domains.Domain>
<java.util.concurrent.CopyOnWriteArrayList/>
</entry>
</domainCredentialsMap>
</com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty>
<hudson.tasks.Mailer_-UserProperty plugin="mailer@463.vedf8358e006b_">
<emailAddress>34556676@qq.com</emailAddress>
</hudson.tasks.Mailer_-UserProperty>
<hudson.plugins.emailext.watching.EmailExtWatchAction_-UserProperty plugin="email-ext@2.102">
<triggers/>
</hudson.plugins.emailext.watching.EmailExtWatchAction_-UserProperty>
<jenkins.security.LastGrantedAuthoritiesProperty>
<roles>
<string>authenticated</string>
</roles>
<timestamp>1692088861290</timestamp>
</jenkins.security.LastGrantedAuthoritiesProperty>
<hudson.model.MyViewsProperty>
<primaryViewName></primaryViewName>
<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.200.vb_9327d658781">
<providerId>default</providerId>
</org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty>
<hudson.model.PaneStatusProperties>
<collapsed>
<string>buildQueue</string>
</collapsed>
</hudson.model.PaneStatusProperties>
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>#jbcrypt:$2a$10$bWv6UwnueWNxp7ey8aOyCOb1v3gPHRjUTD2R9EUwh76OXLehL93CG</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
<org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl plugin="sshd@3.312.v1c601b_c83b_0e">
<authorizedKeys></authorizedKeys>
</org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl>
<jenkins.security.seed.UserSeedProperty>
<seed>b85cfda70750a377</seed>
</jenkins.security.seed.UserSeedProperty>
<hudson.search.UserSearchProperty>
<insensitiveSearch>true</insensitiveSearch>
</hudson.search.UserSearchProperty>
<hudson.model.TimeZoneProperty>
<timeZoneName></timeZoneName>
</hudson.model.TimeZoneProperty>
<hudson.plugins.favorite.user.FavoriteUserProperty plugin="favorite@2.208.v91d65b_7792a_c">
<data class="concurrent-hash-map">
<entry>
<string>远程开机-选项式</string>
<boolean>true</boolean>
</entry>
</data>
</hudson.plugins.favorite.user.FavoriteUserProperty>
<jenkins.model.experimentalflags.UserExperimentalFlagsProperty>
<flags/>
</jenkins.model.experimentalflags.UserExperimentalFlagsProperty>
</properties>
</user>
查看config文件,可以发现有一个passwordHash节点,该节点对应的就是admin用户加密后的密码。
修改admin密码为 123456
然后修改config文件的passwordHash节点对应的值改为#jbcrypt:2a2a10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>#jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
这样admin用户的密码就变成123456了。
重启Jenkins,然后重新用admin账号登录,密码123456就行了。