Is there a way to reset all (or just disable the security settings) from the command line without a user/password as I have managed to completely lock myself out of Jenkins
?
相关问题
- Is shmid returned by shmget() unique across proces
- “Zero out” sensitive String data in Swift
- how to get running process information in java?
- High cost encryption but less cost decryption
- Error building gcc 4.8.3 from source: libstdc++.so
Copy the password from the initialAdminPassword file and paste it into the Jenkins.
We can reset the password while leaving security on.
The config.xml file in /var/lib/Jenkins/users/admin/ acts sort of like the /etc/shadow file Linux or UNIX-like systems or the SAM file in Windows, in the sense that it stores the hash of the account's password.
If you need to reset the password without logging in, you can edit this file and replace the old hash with a new one generated from bcrypt:
This will output your hash, with prefix 2a, the correct prefix for Jenkins hashes.
Now, edit the config.xml file:
Once you insert the new hash, reset Jenkins:
(if you are on a system with systemd):
You can now log in, and you didn't leave your system open for a second.
changing the
<useSecurity>true</useSecurity>
to<useSecurity>false</useSecurity>
will not be enough, you should remove<authorizationStrategy>
and<securityRealm>
elements too and restart your jenkins server by doingsudo service jenkins restart
.remember this, set
<usesecurity>
tofalse
only may cause a problem for you, since these instructions are mentioned in thier official documentation here.To reset it without disabling security if you're using matrix permissions (probably easily adaptable to other login methods):
config.xml
, setdisableSignup
tofalse
.config.xml
, duplicate one of the<permission>hudson.model.Hudson.Administer:username</permission>
lines and replaceusername
with the new user.disableSignup
back totrue
inconfig.xml
.Optional cleanup:
<permission>
line inconfig.xml
.No securities were harmed during this answer.
I had a similar issue, and following reply from ArtB,
I found that my user didn't have the proper configurations. so what I did:
Note: manually modifying such XML files is risky. Do it at your own risk. Since I was already locked out, I didn't have much to lose. AFAIK Worst case I would have deleted the ~/.jenkins/config.xml file as prev post mentioned.
**> 1. ssh to the jenkins machine
under
add:
Now, you can go to different directions. For example I had github oauth integration, so I could have tried to replace the authorizationStrategy with something like below:
Note:, It worked in my case because I had a specific github oauth plugin that was already configured. So it is more risky than the previous solution.
On the offchance you accidentally lock yourself out of Jenkins due to a permission mistake, and you dont have server-side access to switch to the jenkins user or root... You can make a job in Jenkins and add this to the Shell Script:
Then click Build Now and restart Jenkins (or the server if you need to!)