What is GitHub ?
On this page
GitHub is an online platform for storing, sharing, and collaborating on code projects. It’s built around Git, a version control system that tracks changes in files, especially useful for software development.
The goal of this lesson is to learn how to link your local server directory to your online git repository using SSH key pairs. SSH key pairs provide way more safety than just using a password. After GitHub's new update, passwords are no longer accepted, so this link can only be achieved through SSH key pairs.
Step 1: Install and Configure Git
Install Git.
apt install git -yConfigure Git.
git config --global user.name "YourGitHubUsername"
git config --global user.email "your-email@domain.com"You can now check your configuration by using this command.
git config --global --listStep 2: Generate SSH Key and Connect
Generate a new key pair, if not already created. Do not set a passphrase.
ssh-keygen -t ed25519 -C "your-email@domain.com"This command creates a new SSH key pair (a public and private key) using the ed25519 encryption algorithm. Both keys will be saved in the /.ssh directory unless you specify another directory.
Now copy the public key from the directory to put on GitHub. The private key stays on your server.
cat ~/.ssh/id_ed25519.pubWhat this does:
- cat = display file contents
- ~ = your home directory
/home/angelo-mouawad
Add it to GitHub:
- Go to GitHub then settings
- Press the SSH and GPG keys tab
- Press New SSH key
- Finally paste your public key and give it a name
Step 3: Test the SSH Connection
Add GitHub to known hosts.
ssh-keyscan github.com >> ~/.ssh/known_hostsNow test the SSH connection.
ssh -T git@github.comOutput.
root@angelo:/# ssh -T git@github.com
Hi ! You've successfully authenticated, but GitHub does not provide shell access.Finally create a private GitHub repository. Make sure the repository is private otherwise people will have access to your files.
On GitHub:
- Press New Repository
- Give your repository a name like
sasm-lab - Make sure your set the visibility to private
- Don’t add a README or License
Step 4: Link Local Directory to GitHub Repository
Initialize git.
cd /etc
git initAdd SSH remote.
git remote add origin git@github.com:angelo-mouawad/sasm-lab.gitVerify your remote was added by listing all remotes.
git remote -vStep 5: Configure gitignore
Edit the .gitignore file.
nano /etc/.gitignoreWhat this does:
- nano = creates file and then opens it in nano editor
File contents for /etc/.gitignore.
# System junk
*.swp
*.tmp
*.log
# Editor backups
*~
# Cache / runtime
_pycache_/
*.pid
# Server-specific stuff
yoda/
node_modules/
.env
incron.d/etc.confStep 6: Add Commit Push
Add your changes.
git add .gitignore hostsCommit your changes.
git commit -m "Initial commit: added .gitignore and hosts"Push your changes.
git push -u origin master