How to Install Jenkins on an AWS EC2 Server and Access It Securely

DevOps Advocate | Passionate about bridging development & operations to build seamless, scalable systems. Let’s connect and geek out over DevOps, open-source, or the latest in cloud innovation! ✨ Building the future, one pipeline at a time.
Jenkins is a powerful open-source automation server that helps developers automate parts of the software development process. In this guide, I'll walk you through installing Jenkins on an AWS EC2 Linux server and accessing it securely from your browser.
Prerequisites
An AWS EC2 instance (Ubuntu recommended)
SSH access to your EC2 instance
Basic familiarity with Linux commands
Step 1: Install Java (Jenkins Dependency)
Jenkins requires Java to run. Execute the following commands to install OpenJDK 17:
sudo apt update
sudo apt install fontconfig openjdk-17-jre -y
Verify the installation:
java --version
You should see output confirming the installed Java version.
Step 2: Install Jenkins
1. Add Jenkins Repository Key
Run the following commands to add Jenkins’ official repository:
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian/jenkins.io-2023.key
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
2. Update and Install Jenkins
sudo apt-get update
sudo apt-get install jenkins -y
3. Verify Jenkins Installation
Check if Jenkins is running:
sudo systemctl status jenkins
You should see active (running) in the output.
Step 3: Access Jenkins from Your Browser
1. Open Port 8080 in AWS Security Group
Jenkins runs on port 8080 by default. To access it:
Go to the AWS Management Console → EC2 Dashboard.
Select your instance and click on the Security Group linked to it.
Click Edit inbound rules and add:
Type: Custom TCP
Port range: 8080
Source:
0.0.0.0/0(for testing) or restrict it to your IP for better security.
2. Get Your EC2 Public IP
Find your instance’s Public IPv4 address in the EC2 dashboard.
3. Access Jenkins in Browser
Open your browser and enter:
http://<EC2_PUBLIC_IP>:8080
Replace <EC2_PUBLIC_IP> with your instance’s public IP.
4. Unlock Jenkins
The first time you access Jenkins, it will ask for an initial admin password. Retrieve it using:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Paste the password into the Jenkins setup page and proceed with the installation.
Optional: Secure Jenkins Further
Use HTTPS: Set up an SSL certificate with Nginx/Apache as a reverse proxy.
Restrict IP Access: Instead of
0.0.0.0/0, allow only your IP in the security group.Enable Authentication: Configure Jenkins user roles for better security.
Conclusion
You’ve successfully installed Jenkins on an AWS EC2 server and accessed it via a web browser. Jenkins is now ready to automate your CI/CD pipelines!
If you run into issues, check:
sudo systemctl status jenkins(for service status)/var/log/jenkins/jenkins.log(for logs)
Let me know in the comments if you need help! 🚀
Further
Go to official Jenkins Page: https://www.jenkins.io/doc/book/installing/linux/#debianubuntu



