How to setup SSH keys | How to setup Repo in GitHub and Setup Java Project in GitHub | How to add a project in GitHub
GitHub is one of the popular git-based version control systems. GitHub is very good example for Software-as-a-service, hosted on cloud. Let us learn how to create SSH keys and securely connect from EC2 instance. We will also learn how to create a Java Project using Maven and Upload Java Project into GitHub.
Git is a purely distributed version control system.
Pre-requistes:
1. GitHub account
2. Git client installed
3. Connect to your Jenkins EC2 instance
Step # 1 - Create private repository in GitHub.com
Go to https://github.com/
Click on New to create a new repo
Also choose initialize with repository with a README option.
Step # 2 Create SSH keys from your source machine
Login to your Jenkins EC2 instance using Git bash. make sure you are connected to Ec2 instance by ssh url. Type ssh-keygen (and then simply enter four times, do not give any password). ssh-keygen will generate two keys - public keys and private keys. We need to upload the public keys into GitHub.
sudo cat ~/.ssh/id_rsa.pub
Step # 3 - Upload SSH Keys in 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

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 MyApplicationRepo
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.
mvn archetype:generate -DgroupId=com.dept.app -DartifactId=MyWebApp -DarchetypeArtifactId=maven-ar chetype-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 *
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
git push










No comments:
Post a Comment