📖 Scenario: You have just installed Jenkins, a popular automation server. To start using Jenkins securely, you need to create the first admin user. This user will have full control over Jenkins and can manage other users and settings.
🎯 Goal: Learn how to create the first admin user in Jenkins by editing the configuration file and verifying the user creation.
📋 What You'll Learn
Create the initial Jenkins security configuration file with no users
Add a configuration entry for the first admin user with username and password
Apply the configuration to Jenkins by restarting or reloading
Verify the admin user creation by checking the Jenkins users directory
💡 Why This Matters
🌍 Real World
Creating the first admin user is a critical step after installing Jenkins to secure the server and manage access.
💼 Career
Understanding Jenkins user management is essential for DevOps engineers and system administrators to maintain secure CI/CD pipelines.
Create a file named config.xml with the root element hudson.security.HudsonPrivateSecurityRealm_-Details and no users inside it.
Jenkins
Hint
This XML file defines Jenkins security realm details. Start with an empty root element.
2
Add first admin user configuration
Inside the config.xml, add a user element with id set to admin and a passwordHash element with the value {SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 (which is the SHA-1 hash for password 'password').
Jenkins
Hint
The passwordHash uses SHA-1 hash format. Use the exact hash string given.
3
Apply configuration by restarting Jenkins
Write the shell command sudo systemctl restart jenkins to restart Jenkins and apply the new user configuration.
Jenkins
Hint
Use systemctl restart jenkins with sudo to restart the Jenkins service.
4
Verify admin user creation
Write the shell command ls /var/lib/jenkins/users/admin to check if the admin user directory exists.
Jenkins
Hint
If the directory exists, the command will list the 'admin' folder, confirming the user creation.
Practice
(1/5)
1. Why is it important to create the first admin user in Jenkins?
easy
A. To speed up the build process
B. To secure the Jenkins server by controlling access
C. To reduce the server's memory usage
D. To automatically install plugins
Solution
Step 1: Understand Jenkins security basics
Jenkins requires an admin user to control who can access and manage the server.
Step 2: Recognize the role of the first admin user
This user sets permissions and protects the server from unauthorized access.
Final Answer:
To secure the Jenkins server by controlling access -> Option B
Quick Check:
Security = Control access [OK]
Hint: First admin user controls access and security [OK]
Common Mistakes:
Thinking admin user speeds up builds
Confusing admin user with plugin installer
Believing admin user reduces memory use
2. Which of the following is the correct syntax to create a new admin user using Jenkins Groovy script console?
easy
A. jenkins.createUser('admin', 'password')
B. Jenkins.instance.createUser('admin', 'password')
C. Jenkins.security.createAccount('admin', 'password')
D. jenkins.model.Jenkins.instance.securityRealm.createAccount('admin', 'password')
Solution
Step 1: Recall Jenkins Groovy script for user creation
The correct method to create a user is via the securityRealm's createAccount method.
Step 2: Match the exact syntax
jenkins.model.Jenkins.instance.securityRealm.createAccount('admin', 'password') is the valid syntax.
Final Answer:
jenkins.model.Jenkins.instance.securityRealm.createAccount('admin', 'password') -> Option D
Quick Check:
securityRealm.createAccount = correct syntax [OK]
Hint: Use securityRealm.createAccount to add users [OK]
Common Mistakes:
Using Jenkins.instance.createUser which does not exist
Calling jenkins.createUser directly
Using Jenkins.security.createAccount which is invalid
3. What will be the result of running this Groovy script in Jenkins script console?