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

Wednesday, June 30, 2021

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

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-requistes:

  • 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.



Monday, August 19, 2019

How will you establish connection securely between two systems without password, but secured way?

How will you establish connection securely between two systems without password, but secured way?
1. Create keys using ssh-keygen command in source machine. This will create private and public keys.
2. upload the public keys into target machine
3. then do ssh into target_node_ip.
once public keys uploaded, client can talk to server securely without password.




Wednesday, August 14, 2019

How to test SSH connection keys added in Bitbucket or GitHub?

How to test SSH connection keys added in Bitbucket or GitHub?

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.



Wednesday, August 7, 2019

How to copy SSH keys from one machine to other machine - How to transfer SSH keys into target server

Let's say you have two servers - Host_A & Host_B, you would like to copy SSH keys from A to B. You need to generate keys and use ssh-copy-id command to transfer keys from source machine to target machine.

1. Generate Keys

ssh-keygen

use the above command to generate SSH keys on source machine.

Enable Password Authentication

Open sshd_config file

sudo vi /etc/ssh/sshd_config






Enable password authentication by changing to yes

Restart ssh service

sudo service sshd restart

2. ssh-copy-id

ssh-copy-id Host_B

say yes and enter


After this, make suue you are able to ssh into Host_B

ssh Host_B


Sunday, January 20, 2019

How to add SSH keys into Bitbucket from your machine? - Create SSH keys and upload into BitBucket

Let us see how to create SSH keys in your machine and upload into Bitbucket so that you can start checking code into Bitbucket.

Pre-requistes: 

Git installed on your machine by downloading from the below URL:
https://git-scm.com/downloads

Steps:
1. First create SSH keys by entering the below command.
ssh-keygen 
(and then simply enter four times, do not give any password)

2. the above command should create two keys - public keys and private keys.
copy the content of public key executing below command in Gitbash.
 
sudo cat ~/.ssh/id_rsa.pub

3. Now go to bitbuket.org
4. now click on your avatar (left bottom of the screen, and BitBucket settings-> security--> ssh keys
5. go to click on Add key,  and paste the content of public key. give some name as mySSH key. click on Add key.
6. Now click on repo you would like to check in or make code changes. 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.  

git clone <ssh_url_from_bitbucket_repo_you_created>  

7. That should create a folder in your machine. type ls -al
8. cd into repo name
9. Make code changes now