0
0
Jenkinsdevops~5 mins

Creating first admin user in Jenkins - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
When you install Jenkins for the first time, you need to create an admin user to securely manage your Jenkins server. This user has full control to configure and run jobs.
Right after installing Jenkins to secure access.
When setting up Jenkins on a new server for your team.
When you want to restrict who can change Jenkins settings.
Before creating any build jobs to keep your server safe.
When you want to manage users and permissions centrally.
Commands
This command shows the initial admin password Jenkins generates during installation. You need this password to unlock Jenkins the first time you open it in your browser.
Terminal
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Expected OutputExpected
3f4e5d6c7b8a9e0f1d2c3b4a5e6f7d8c
This command creates the first admin user by sending the required user details to Jenkins setup wizard API. It automates the web form submission.
Terminal
curl -X POST http://localhost:8080/setupWizard/createAdminUser \
  --data-urlencode 'username=admin' \
  --data-urlencode 'password1=AdminPass123' \
  --data-urlencode 'password2=AdminPass123' \
  --data-urlencode 'fullname=Administrator' \
  --data-urlencode 'email=admin@example.com'
Expected OutputExpected
{"status":"success","message":"Admin user created"}
-X POST - Specifies the HTTP POST method to send data.
--data-urlencode - Encodes and sends form data fields.
This command verifies that the admin user was created by accessing Jenkins API with the new admin credentials.
Terminal
curl -u admin:AdminPass123 http://localhost:8080/api/json
Expected OutputExpected
{"assignedLabels":[{}],"mode":"NORMAL","nodeDescription":"the master Jenkins node","numExecutors":2,"description":null,"jobs":[],"overallLoad":{},"primaryView":{"name":"All"},"quietingDown":false,"slaveAgentPort":50000,"unlabeledLoad":{},"useCrumbs":true,"useSecurity":true,"views":[{"name":"All"}]}
-u admin:AdminPass123 - Uses basic authentication with admin username and password.
Key Concept

If you remember nothing else from this pattern, remember: Jenkins creates a temporary initial admin password that you must use to unlock and create your first admin user.

Common Mistakes
Trying to access Jenkins before reading the initial admin password.
Jenkins will not let you proceed without unlocking it first using the initial password.
Always read the initial admin password from the secrets file before accessing Jenkins the first time.
Skipping the admin user creation and leaving Jenkins unsecured.
Without an admin user, Jenkins is open and vulnerable to unauthorized access.
Complete the admin user creation step immediately after unlocking Jenkins.
Using weak or default passwords for the admin user.
Weak passwords make your Jenkins server easy to hack.
Choose a strong, unique password for the admin user.
Summary
Read the initial admin password from Jenkins secrets to unlock the server.
Create the first admin user by submitting user details to Jenkins setup API.
Verify admin user creation by accessing Jenkins API with new credentials.