1. Overview

Jenkins is an automation tool that offers various plugins to integrate various tools, such as version control systems, testing frameworks, and deployment tools. During Jenkins installation, a user named jenkins gets created to run the Jenkins service. The Jenkins server uses this user to run processes and perform critical operations. The user jenkins may not be able to be accessed after installation for various reasons.

In this tutorial, we’ll learn how to log in as a user jenkins after installation.

2. Understanding the Problem

When it comes to setting up Jenkins on a Linux system, one of the first steps is to create a separate user specifically for the Jenkins service. This is an important security measure as it permits Jenkins to run with its default set of permissions, separate from the permissions of the user who installed it. Additionally, if a security breach or accident occurs, it won’t affect the entire system.

Sometimes after installing Jenkins, users experience trouble switching to the jenkins user using the su command. This means that it won’t be able to perform certain actions or tasks that require Jenkins permissions. We may face this issue due to incorrect configuration settings for the jenkins user. Furthermore, permissions must be set correctly in order to perform the necessary tasks.

3. User Doesn’t Exist

One potential cause of this issue is that the jenkins user simply doesn’t exist on our system. We must create the jenkins user before switching over. To check if a jenkins user exists or not, we can use the –u option with the id command:

$ sudo id -u jenkins
id: ‘jenkins’: no such user

In the above output, we can see that the jenkins user doesn’t exist on this system. We can create a user named jenkins using the useradd command:

$ sudo useradd jenkins

The above command successfully creates the jenkins user on Linux.

4. Invalid Shell Configuration

We also can run into this problem when jenkins user doesn’t have valid shell configurations. Linux distributions restrict users from using certain shells. Furthermore, we can’t switch to user jenkins using the su command if it doesn’t have a valid shell. We can use the grep command with the /etc/passwd file to find out the current shell option of the jenkins user. Let’s look at the command:

$ sudo cat /etc/passwd  | grep jenkins | awk -F: '{print $7}'
/usr/sbin/nologin

We can see that no shell is assigned to the jenkins user. Using the usermod command in Linux, we can set the shell to the jenkins user:

$ sudo usermod -s /bin/bash jenkins

Make sure that we have root privilege to run the usermod command. It is necessary to restart the Jenkins server for the changes to take effect.

5. Password Not Set

We can also face this issue when the jenkins user has no password set. The su command needs a password to switch to another user. Furthermore, if the jenkins user has no password, we won’t be able to switch to that user with the su command. We can use the grep command with the /etc/shadow file to determine if a user has set a password or not:

$ sudo grep jenkins /etc/shadow | cut -d':' -f2
!!

In the above output, we can see that the jenkins user has no password. Furthermore, to set a password for that user, we can use the passwd command:

$ sudo passwd jenkins

On executing the above command, the system will prompt us to enter and confirm the newly created password for the jenkins user.

6. Conclusion

In this article, we explored several solutions for not being able to su to the jenkins user after installation. We can encounter this error for various reasons, such as the jenkins user doesn’t exist, the user doesn’t have a valid shell, or the user doesn’t have a password. In order to access jenkins, we should check each of these possibilities and fix them.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.