Title: Securely Interacting with Jenkins via SSH: A Step-by-Step Guide

?? What You'll Learn:

In this post, we'll explore how to configure SSH access for a user in Jenkins, enabling secure interactions with the Jenkins server. We'll cover setting up a public SSH key, configuring the Jenkins SSH service, and executing commands over SSH. This guide is perfect for DevOps engineers looking to enhance their CI/CD pipeline security and efficiency.


?? Step 1: Assigning a Public SSH Key to a User

I assigned a public SSH key to a user named Mike, allowing him access to the Jenkins server. This setup enables Mike to perform actions based on his assigned role.

checking Jinkens.ssh-pub file which cantina SSH Access key Path /.ssh


SSH Access key


pasted in user settings

?? Step 2: Configuring the SSH Service in Jenkins

We've configured the SSH service in Jenkins to listen on a specific port. To determine the port being used, run the following command:

curl -Lv https://localhost:8085/login 2>&1 | grep -i 'x-ssh-endpoint'        

This command helps us identify the SSH endpoint port, ensuring we can connect to the Jenkins server securely.


?? Step 3: Interacting with Jenkins over SSH

With the SSH port identified, Mike can now interact with Jenkins over SSH. Using Mike's credentials, run the following command:

ssh -i /home/mike/.ssh/jenkins_key -l mike -p 8022 jenkins-server help        

Key options:

  • -i specifies Mike's private SSH key. We've already added the public key in the Jenkins configuration.
  • -l indicates the login user, which is Mike in our scenario.
  • -p specifies the port, which we previously identified as 8022.


?? Step 4: Restarting Jenkins Safely from the CLI

Using the help command, find the built-in command to safely restart Jenkins from the CLI. This ensures that Jenkins is restarted without affecting ongoing operations or builds.

By following these steps, you can securely manage Jenkins operations via SSH, enhancing your CI/CD workflows.


Feel free to engage with this post by sharing your thoughts or any additional tips you have for working with Jenkins and SSH! #DevOps #Jenkins #CI/CD #SSH #Automation

要查看或添加评论,请登录

Aniket Purohit的更多文章

社区洞察

其他会员也浏览了