Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Tuesday, June 29, 2021

How to Integrate Jenkins and GitHub using SSH keys? | Jenkins and GitHub Integration

GitHub removed password authentication support from August 13, 2021 instead it recommends to use either OAuth or Personal Access Token. We will see how to connect to GitHub from Jenkins using SSH keys instead of using user name and password.

It is also a good practice to use SSH keys in Jenkins jobs instead of using user name and password.


Watch the steps in YouTube channel:

Pre-requisites:

  • Jenkins is up and running
  • Credentials plug-in installed in Jenkins

Create SSH keys in your Jenkins EC2 instance

ssh-keygen

enter four times. this will create keys in .ssh folder.

Copy and paste the public key
sudo cat ~/.ssh/id_rsa.pub

Add public Keys into your respective GitHub

Add public keys into your Repository--> settings--> Deploy keys section




Click on Add Deploy Key and enter public keys and save.

Add Private Keys in Jenkins Master
Login Jenkins. Go to Manage Jenkins. click on Credentials



Click on Jenkins


Click on Global Credentials



Click on Add Credentials


Choose SSH username with private key






Choose SSH username with private key
username can be anything
Click on enter directly under private key option and Click Add


Copy and paste private key(not public key) of your from Jenkins instance. command is below:
sudo cat ~/.ssh/id_rsa

copy the content of whole output from above command.
Click OK to save.

Now go to any Jenkins Job, you can choose this option for checking out from GitHub. Make sure you enter SSH url not https url.




That's it. This is how you use SSH url and private keys to checkout code from bitbucket or Github without entering username/password in Jenkins.


Click here to authenticate with GitHub using Personal Access Token.

Friday, September 20, 2019

How to setup SSH keys in Bitbucket and Setup Java Web App in BitBucket | How to add a Java Web App in BitBucket using Maven

BitBucket is one of the popular git-based version control systems. BitBucket is very good example for Software-as-a-service, hosted on cloud. Let us learn how to setup a Java web project in BitBucket.

Git is a purely distributed version control system. Click here to learn more about Git and its advantages over other SCMs.

Please find below steps for how to setup SSH keys in Bitbucket from EC2 instance and also how to setup Java Web App using Maven in BitBucket.



Pre-requistes:
If you don't have an bitbucket account, You need to create an account in bitbucket.org.

Implementation steps:

1. after login into bitbucket, click on + and Click on Create Repository



2. enter the repo name as MyBitbucketRepo, make sure it is private, Include read me option - choose yes with template. Click Git as version control system.

3. Click on create repository.
4. now click on your avatar (left bottom of the screen, BitBucket settings-> security--> ssh keys
5. now go to your laptop, open git bash for windows laptop or iTerm (for iMac laptop) and connect to Jenkins EC2 instance using Git bash. 

How to connect, refer this url - http://www.cidevops.com/2018/02/how-to-connect-to-ec2-instance-from.html

6. Now type  ssh-keygen (and then simply enter four times, do not give any password)


If you already have keys generated, you can use existing key. You don't have to over write the old key.

7. copy the content of public key executing below command in Gitbash.
sudo cat ~/.ssh/id_ed25519.pub
8. go to click on Add key from step # 3,  and paste the content of public key. give some name as mySSH key. click on Add key.
9. Now click on repo you created in step # 1. Click on Clone and copy the SSH url. Do not select HTTPS Url. The url will be from your repo you created under Clone link. 

10. go back to Gitbash  windows connected to Jenkins EC2, execute the below command. Paste the SSH url you copied above. 


git clone <ssh_url_from_bitbucket_repo_you_created>


11. Now after cloning, type ls -al command
12. It will show a folder with repo name..
13. navigate to repo folder by below command:
cd mybitbucketrepo

14. use below command to create Java project using Maven. Maven is the build for creating and building java projects.
mvn archetype:generate -DgroupId=com.dept.app -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
15. type ls -al to see the new folder called MyWebApp
16. type  below command to see the newly created project
git status



17. git add  *


18. Perform below command to commit the changes to local repository first.

git commit -m "my first project check-in to bitbucket"
19. Now perform below command to push from local repository to remote repository.

git push
You can also watch actual demo with video here below:
 

Wednesday, August 14, 2019

How to test SSH keys were added in Bitbucket or GitHub successfully?

How to test your SSH keys were added in Bitbucket or GitHub successfully?

BitBucket
ssh -T git@bitbucket.org
logged in as <user_name>

You can use git or hg to connect to Bitbucket. Shell access is disabled

GitHub
ssh -T git@github.com
Hi <user-name>! You've successfully authenticated, but GitHub does not provide shell access.



Saturday, May 18, 2019

How to setup SSH keys | How to setup Repo in GitHub and Setup Java Project in GitHub | How to add a Java Web App in GitHub using Maven

GitHub is one of the popular git-based version control systems. GitHub is very good example for Software-as-a-service, hosted on cloud for storing and sharing code. 

We will learn how to create a Java Project using Maven and push Java Project into GitHub from Ec2 instance. Let us learn how to create SSH keys and securely connect to gitHub from EC2 instance. 

Git is a purely distributed version control system. Click here to learn more about Git and its advantages over other SCMs.


Pre-requisites:

1. GitHub account
2. Git client installed
3. Connect to your Jenkins EC2 instance

Step # 1 - Create private repository in GitHub

Click on New to create a new repo 
Also choose initialize with repository with a README option.

Step # 2 Create SSH keys from your Jenkins EC2 machine

Login to your Jenkins EC2 instance using Git bash. (make sure you are connected to Jenkins instance)
Type ssh-keygen (and then click on enter four button times, do not give any password). 
ssh-keygen command will generate two keys - public keys and private keys. We need to upload only the public keys into GitHub.

If you already have keys generated, you can use the existing key, you don't have to overwrite the existing key. 

Now copy the content of public key by executing below command in Git bash:
sudo cat ~/.ssh/id_ed25519.pub


Step # 3 - Upload SSH Keys into GitHub
Go to GitHub, click on Settings.
Copy SSH keys Key section and then click on Add SSH key.

Step # 4 - Clone Repo locally

Now click on the Cat icon on your top left to go back to repo you just created.
Click on the repo you created in step # 1, click on Code, under SSH

 




Copy the SSH url and go to your EC2 instance using git bash and perform below command:

git clone <paste the ssh url >

type yes to connect

After you clone, you should see something below:







type below command to list the directory
ls -al
The above command should list the directory you have cloned.

Now go into repo folder (red circled like above) you have cloned.
cd <replace_your_repo_folder_name>

Step # 5 - Create Java Web App using Maven
use below maven command to create Java Web App using Maven. Maven is the build for creating and building java projects. Click here to know more about Maven.

mvn archetype:generate -DgroupId=com.dept.app -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Step # 6 - Push Java Web App using Git commands into GitHub

type below command to see the new folder called MyWebApp
ls -al

type  below command to see the newly created project in red color
git status

Now add the newly created folder by executing below command:
git add  *

Now make sure all the files are moved to staging area, when you execute below command:
git status

git config --global user.name "your github user_id"
git config --global user.email "youremailid"

Perform below command to commit the changes to local repository first.
git commit -m "my first project check-in to GitHub"

Now perform below command to push from local repository to remote repository. 

git push

 

Verify code changes in GitHub

Now to GitHub and click on the repo, you will see your commits.


You can also watch the videos of the above lab exercise in my YouTube channel given below:






🚀 Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp – Sep 2026

Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp from Coach AK - Sep 2026 Schedule