Issue
After creating a fresh EC2 server machine, I am able to SSH into it. From this SSH session, I am able to install the required software to run Jenkins on it. I am able to make basic pipelines and do standard work on the Jenkins which is running perfectly fine.
Below are the commands I am using to setup the Jenkins on the machine-
sudo apt update
sudo apt install -y openjdk-11-jdk
sudo apt install -y maven
sudo apt install unzip wget
wget -p -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install -y jenkins
sudo systemctl start jenkins
sudo ufw allow 8080
sudo ufw enable
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
After this, if I close the SSH session and try to reconnect to the EC2, I am not able to do so.
The SSH is possible only before installing the Jenkins. Is Jenkins somehow disabling the SSH login into machine? I am new to this and could use some help.
Jenkins Version - Jenkins 2.357 EC2 - Ubuntu 20.04 Sec Groups - Allows All Traffic plugins installed - Default suggested plugins at startup
Solution
As suggested by John in the comments, I added sudo ufw allow 22
after installing the jenkins to allowing the traffic.
Also, the gpg keys for the installation of the Jenkins got outdated. The fresh steps for installation of Jenkins can be found here.
Answered By - Ayush Adarsh
Answer Checked By - Candace Johnson (JavaFixing Volunteer)