解决登陆Jenkins忘记admin默认密码的情况

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用户加密后的密码。

解决登陆Jenkins忘记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就行了。

声明: 本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
持续集成

DevOps 工程师必备的 6 个 Linux 命令行工具

2024-12-9 12:17:10

Linux

宝塔Linux面板移除.user.ini文件失败解决办法

2024-12-12 18:30:35

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索