How to Create a Jenkins User on Ubuntu? [2 Methods]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The open-source automation server Jenkins can easily be deployed and run on Linux distributions. The first step to using Jenkins would be creating a new user. In this article, I will show you how to create a Jenkins user on Ubuntu along with installing and setting up the very first admin user in Jenkins.

Key Takeaways

  • Creating a new Jenkins user on Ubuntu using both GUI & CLI.
  • Installing Java on Ubuntu.
  • Installing Jenkins on Ubuntu.
  • Adding Jenkins Admin.

Requirements

Downloads

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSFlowchart of create Jenkins user in Ubuntu

Watch 2 Methods to Create a Jenkins User on Ubuntu

2 Methods to Create a Jenkins User on Ubuntu

There are several ways of creating a new Jenkins user. However, the task can be divided into two main methods: creating a new Jenkins user using CLI(Command Line Interface) and creating a new Jenkins user using GUI(Graphical User Interface). In this section, I will illustrate both methods of creating a Jenkins user in Ubuntu.

You can read our Comparative Analysis of Methods to distinguish between these two methods and best pick one for your needs.

Method 01: Using CLI to Create a Jenkins User on Ubuntu

You can create a Jenkins user from your Ubuntu CLI. To use this method first you will need to download the ‘jenkins-cli.jar’ in your Ubuntu system which will enable you to remotely run Jenkins commands. Additionally, with this approach, you can set the user password at the same time.

In this section, I will create a new Jenkins user named “jenkins_user1” from CLI. I will set the account’s password to “user123”. You can do the same by following the steps below.

Steps to Follow >

  1. At first, open the Ubuntu terminal.
  2. Then, move to your Jenkins folder using the command below.
    cd /var/lib/jenkins
    EXPLANATION
    • cd: Changes directory location.
    • /var/lib/jenkins: Path to the Jenkins.
  3. Now, download the jar file by running the following command or you can download it from this article.
    sudo wget localhost:8080/jnlpJars/jenkins-cli.jar
    EXPLANATION
    • sudo: Grants administrative privileges.
    • wget: Allows users to download files using
      different protocols.
    • localhost:8080/jnlpJars/jenkins-cli.jar: URL to the .jar file.
  4. Finally, create new user with the given command.
    echo 'jenkins.model.Jenkins.instance.securityRealm.createAccount("jenkins_user1", "user123")' | java -jar ./jenkins-cli.jar -s "http://localhost:8080" -auth jenkins_admin:linuxsimply -noKeyAuth groovy = –
    EXPLANATION
    • echo: Displays a given text.
    • ‘jenkins.model.Jenkins.instance.securityRealm.createAccount(“jenkins_user1”, “user123”)’: Creates a new user account in Jenkins with the username “jenkins_user1” and the password “user123”.
    • | (Pipe symbol): Used to redirect the output of the first command to the input of the second command.
    • java -jar ./jenkins-cli.jar: Launches the CLI tool.
    • -s “http://localhost:8080“: Specifies the URL of the Jenkins server that the CLI tool should connect to.
    • -auth: Specifies the Jenkins admin username and password.
    • jenkins_admin:linuxsimply: The username and the password of the admin account.
    • -noKeyAuth: Disables the use of SSH key authentication.
    • groovy = –: Specifies that the Groovy script should be read from standard input.

    Creating Jenkins user from Ubuntu CLI.

  5. Moreover, view the newly created user from your Jenkins server. View Jenkins user created from CLI.Upon completion of the aforementioned steps, a new Jenkins user will be created on your server. As you can see in the above image, you can view the newly created user by logging into your Jenkins account from any web browser.

Method 02: Using GUI to Create a Jenkins User on Ubuntu

The second method of creating a new Jenkins user would be by using the GUI. To use the Jenkins GUI, you will have to log in to the Jenkins server from a web browser. In this example, I will create a new Jenkins user named “Tony_stark” from GUI. To do the same you can follow the steps below.

Steps to Follow >

  1. At first, from any web browser visit the Jenkins server connected to your localhost using the following link “http://localhost:8080“.Browsing Jenkins server from GUI.
  2. Then, sign in to your Jenkins admin account by entering the username and password.Signing into Jenkins server from GUI.
  3. Once logged in as the Admin User, navigate and CLICK on the “Manage Jenkins” menu.Navigating to "Manage Jenkins" menu.
  4. Scroll down to find the “Manage Users” option and then CLICK on it.Selecting "Manage Users" option.
  5. Now, PRESS the “Create User” button located in the top right corner.Creating new Jenkins user from GUI.
  6. Finally, fill up the new user credentials and then PRESS the “Create User” button.Entering new user credentials.
  7. You can find the newly created user listed with the Jenkins server’s other available users.Viewing user list.In the image above, you can see that I have successfully created a new Jenkins user from the Jenkins GUI.


Comparative Analysis of Methods

Since this article introduces multiple cases for a single task, you might get confused about which one to pick. Therefore, in this section, I am presenting a comparative analysis of the two different approaches for your convenience. You can learn the advantages and disadvantages of both scenarios and choose what is the best for you.

Methods Pros Cons
Method 1
  • Does not require any web browser.
  • Can create a new user without explicitly logging into the Jenkins server.
  • The username and password can be set up using a single command.
  • Allows to perform the task remotely.
  • Needs a separate .jar file to enable the jenkins CLI commands.
Method 2
  • Does not require any additional file.
  • Visible instructions are available at the Jenkins GUI.
  • Does not need any knowledge of the command line.
  • Requires logging in as the Jenkins server’s admin user.
  • Needs a web browser to open the Jenkins GUI.

Summing up it can be said that all three methods come with their own pros and cons. The suitable method varies from user to user. If you are comfortable with the CLI you can go for Method 1. On the other hand, If you do not have any idea about the Linux commands, you can use the approach through GUI.

Complementary Information

Besides, knowing about creating a new Jenkins user on Linux, you will find the below information helpful.

Install Java on Ubuntu

Although your Ubuntu can contain a Java package, but it may not be up to date. Therefore, to get the latest version of the Java package and install it on your system you can follow the instructions below.

Steps to Follow >

  1. Open the Ubuntu terminal.
  2. Update the packages on your machine with the command below.
    sudo apt update
    EXPLANATION
    • sudo: Grants administrative privileges.
    • apt: Manages available packages on the system.
    • update: Updates available packages.
  3. Give the password for your current logged-in user and press ENTER.Updating existing packages in Ubuntu.
  4. Then, install the Java package using the following command.
    sudo apt install openjdk-11-jre
    EXPLANATION
    • sudo: Grants administrative privileges.
    • apt: Manages available packages on the system.
    • install: Installs packages on the system.
    • openjdk-11-jre: Package name of the open-source JDK.
    Installing Java on Ubuntu.
  5. Finally, check the installed Java version with the command below.
    java -version
    EXPLANATION
    • java -version: Displays installed Java version.
    Viewing installed Java version on Ubuntu.In the above image, I have installed the Java package on my machine by following the above-mentioned steps.


Install Jenkins on Ubuntu

By default, Ubuntu does not offer any Jenkins package. Therefore, to get the latest version I will download the Jenkins package and install it on my system. Follow the instructions below to do the same.

Steps to Follow >

  1. At first, launch the Ubuntu terminal.
  2. Then, run the given command to add the GPG key to your system
    curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    EXPLANATION
    • curl -fsSL: Silently downloads files from a URL and shows errors if they occur.
    • https://pkg.jenkins.io/debian/jenkins.io.key: URL to download Jenkins GPG key.
    • | (Pipe symbol): Used to redirect the output of the first command to the input of the second command.
    • sudo: Grants administrative privileges.
    • tee: Redirects the output of the previous command to a file.
    • /usr/share/keyrings/jenkins-keyring.asc: The filename where the output is redirected to.
    • > /dev/null: Redirects the output of the tee command to the null device, which discards it.
  3. Now, add the Jenkins binary packages to your sources using the given command.
    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
    EXPLANATION
    • echo: Displays a given text.
    • deb: Specifies the package repository type.
    • [signed-by=/usr/share/keyrings/jenkins-keyring.asc]: Specifies the location of the GPG public key file needed to authenticate packages.
    • https://pkg.jenkins.io/debian binary/: URL of the package repository that contains the binary Jenkins packages.
    • | (Pipe symbol): Used to redirect the output of the first command to the input of the second command.
    • sudo: Grants administrative privileges.
    • tee: Redirects the output of the previous command to a file.
    • /etc/apt/sources.list.d/jenkins.list: The filename where the output is redirected to.
    • > /dev/null: Redirects the output of the tee command to the null device, which discards it.
  4. To update the newly downloaded packages use the command below.
    sudo apt-get update
    EXPLANATION
    • sudo: Grants administrative privileges.
    • apt-get: Manages the latest versions of available packages on the system.
    • update: Updates available packages.

    Download and update packages for installing Jenkins in Ubuntu.

  5. Finally, install the Jenkins server with the following command.
    sudo apt-get install jenkins
    EXPLANATION
    • sudo: Grants administrative privileges.
    • apt-get: Manages available packages on the system.
    • install: Installs packages on the system.

    Installing Jenkins server in Ubuntu.In the above image, you can see that I have installed the Jenkins service on my machine by following the above-mentioned steps. To set up the server follow the procedure explained next.

Create a Jenkins Admin User on Ubuntu

After the successful installation of the Jenkins package, you will need the start the server on your system and set up an Admin User. Follow the below process to complete these tasks.

Step1: Starting Jenkins Server on Ubuntu

To start the Jenkins server in Ubuntu go through the given instructions.

Steps to Follow >

  1. At first, go to your Ubuntu terminal.
  2. Then, enable the Jenkins service with the following command.
    sudo systemctl enable jenkins
    EXPLANATION
    • sudo: Grants administrative privileges.
    • systemctl: Manages system services.
    • enable jenkins: Enables the Jenkins.
  3. Now, start the Jenkins server using the given command.
    sudo systemctl start jenkins
    EXPLANATION
    • sudo: Grants administrative privileges.
    • systemctl: Manages system services.
    • start jenkins: Starts the Jenkins.
  4. Additionally, check the status of the Jenkins service using the command:
    sudo systemctl status jenkins
    EXPLANATION
    • sudo: Grants administrative privileges.
    • systemctl: Manages system services.
    • status jenkins: Checks the status of the Jenkins.

    starting Jenkins server in Ubuntu and checking status.

  5. From any web browser visit the Jenkins server connected to your localhost.connecting to Jenkins server from web browser.
  6. The browser will give you a path location of a file to retrieve the Initial Admin Password from your Ubuntu system.Getting initial password location.
  7. Now, go to your Ubuntu terminal and open the “initialAdminPassword” file with sudo privileges using the command below. Copy the password which is displayed on your terminal.
    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    EXPLANATION
    • sudo: Grants administrative privileges.
    • cat: Displays file contents.
    • /var/lib/jenkins/secrets/initialAdminPassword: Path to the Jenkins
      default admin user’s password file.

    Getting initial admin password for Jenkins server.

  8. Then, paste the password that you copied in step 7 to the Administrator password field and PRESS the “ContinueBUTTON.Entering initial password in Jenkins server.
  9. CLICK on the “Install suggested plugins” to install the useful Jenkins plugins.Selecting suggested packages for Jenkins server.
  10. Wait till the installation is complete.Installing packages on Jenkins server.


Step2: Setting Up Jenkins Admin User on Ubuntu

After plugin installation, you can set up the Admin User in Jenkins. Follow the process below to do so.

Steps to Follow >

  1. Firstly, fill up the user credentials and then PRESS the “Save and continue” button.Creating Jenkins admin user.
  2. Then, PRESS the “Save and Finish” button to save the user credentials.Configuring admin user information.
  3. Finally, CLICK the “Start using Jenkins” button to launch the server.Start using Jenkins server in Ubuntu.
  4. Furthermore, navigate to the “People” menu to view the newly created Admin User.Viewing admin user imformation. Upon completion of this section, the Jenkins Admin User will be created and the Jenkins server will require the given username and password for accessing the server.

Conclusion

This article here presents a comprehensive guide to creating a new Jenkins user in Ubuntu. Users of beginner to advanced levels can use the explained methods for achieving their goals. I hope this article will help you get familiar with the Jenkins service in Linux and improve your overall experience.

People Also Ask

Can we create users in Jenkins?
Yes. You can create new users in Jenkins from both Command Line Interface (CLI) and Graphical User Interface(GUI).
What is the Jenkins username and password?
The default Jenkins user’s username is “admin” and the password for the corresponding account is stored at the “/var/lib/jenkins/secrets/initialAdminPassword” file. You can use cat command with sudo keyword to view the password.
How do I access Jenkins on Ubuntu?
To access the Jenkins server from Ubuntu, you must have Java installed on your system. After installing Java, you may install Jenkins services and access it from your Ubuntu distribution.
How do I find my Jenkins password in Ubuntu?
The default Jenkins server’s admin password is stored in the location “/var/lib/jenkins/secrets/initialAdminPassword” of your Ubuntu system. To view the contents of the “initialAdminPassword” file you can run the cat command with sudo keyword.
Where is the Jenkins file in Ubuntu?
By default, the Jenkins configuration file in Ubuntu is located in the “/etc/default/jenkins” directory. The location can vary depending on other Linux distributions.
Relaed Articles

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment