DEV Community

Khalif AL Mahmud
Khalif AL Mahmud

Posted on

Can’t access username or password, forgot these credentials after installing Jenkins

Jenkins is a powerful automation server widely used for continuous integration and delivery (CI/CD). However, users often encounter login-related issues, especially during their first interaction with the system or after a system restart. If Jenkins is now asking for a username and password and you're unsure where to find them, this guide will help you understand why this happens and how to regain access.

Understanding Jenkins Authentication

First-Time Login with Key

During the initial installation of Jenkins, the system uses a key-based authentication mechanism. Typically, an initial admin password is generated and stored in a file within Jenkins' home directory. This password is required to complete the initial setup and configure an admin user.

Subsequent Logins with Username and Password

Once the initial setup is complete, Jenkins requires a username and password for login. If you skipped creating an admin account or forgot the credentials, you’ll need to retrieve or reset them to regain access.

Where to Find Jenkins Credentials

1. Initial Admin Password (First-Time Setup)
The initial admin password is stored in the following locations:

  • Linux Systems: /var/lib/jenkins/secrets/initialAdminPassword

  • Windows Systems: %JENKINS_HOME%\secrets\initialAdminPassword

To retrieve the password:

  • Open the specified file using a text editor or command-line tool.

    • Linux: cat /var/lib/jenkins/secrets/initialAdminPassword
    • Windows: Open the file in Notepad or any text editor.
  • Use the retrieved password along with the username admin to log in.

2. Custom Admin Credentials (After Setup)
If you created an admin account during the setup process, use the username and password you configured. If these are forgotten, proceed to the credential reset steps.

Steps to Resolve Login Issues

Accessing the Initial Admin Password If the setup process is incomplete:

  • Locate the initialAdminPassword file as described above.

  • Log in with admin as the username and the retrieved password.

Resetting Credentials If you’ve already set up an admin user but can’t remember the credentials, here are two ways to reset them:

Option 1: Reset Password via Configuration Files

  • Stop the Jenkins Service:

    • On Linux: sudo systemctl stop jenkins
    • On Windows: Stop the service from the Services application.
  • Edit the config.xml File:

    • Navigate to Jenkins' home directory.
    • Open config.xml and locate the <useSecurity>true</useSecurity> tag.
    • Change it to <useSecurity>false</useSecurity> or remove the tag.
  • Restart Jenkins:

    • On Linux: sudo systemctl start jenkins
    • On Windows: Restart the service from the Services application.
  • Log in without credentials. Re-enable security and set a new admin user.

Option 2: Create a New Admin User via CLI or Script Console

  • Open Jenkins CLI or Script Console.

  • Run the following Groovy script to create a new admin user:

jenkins.model.Jenkins.instance.securityRealm.createAccount('newAdmin', 'newPassword')
Enter fullscreen mode Exit fullscreen mode
  • Log in with the newly created credentials.

Best Practices for Credential Management

  1. Secure Storage: Store Jenkins credentials securely in a password manager.

  2. Regular Backups: Backup Jenkins configuration files and the home directory regularly.

  3. External Authentication: Consider integrating Jenkins with external authentication systems like LDAP or SSO to simplify user management.

Jenkins login issues can be frustrating, but understanding the authentication process and knowing how to retrieve or reset credentials can help you quickly regain access. By following the steps outlined in this guide, you can overcome these challenges and maintain a secure, efficient CI/CD environment.

Need further assistance? Feel free to share your questions or experiences in the comments below!

Top comments (0)