Generate SSH key pair and add to GitHub
ssh-keygen -t rsa -C [email] -f ~/.ssh/[filename]
ssh-keygen -t rsa -C username@gmail.com -f ~/.ssh/github
-t
| Specify encryption type, usuallyrsa
(legacy) ored25519
(current)-C
| Email used to authenticate to your GitHub account-f
| Specify filename for new SSH keys
The command above will create two files:
~/.ssh/github
- Your SSH Private Key~/.ssh/github.pub
- Your SSH Public Key
cat ~/.ssh/github.pub
⚠️
Make sure to add public SSH keys to GitHub
Modify SSH Config File
Open ~/.ssh/config
file using vim. If it does not exist it then it will create one. Then configure the file using the example below (modify to your use case):
vim ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/ssh_keys_github
Host arapitech.com
HostName arapitech.com
User git
IdentityFile ~/.ssh/ssh_keys_arapitech
Add Remote Branch and Clone
Go back to your working directory and add the remote branch
git remote add origin <ssh url from GitHub>
git remote add origin git@github.com:myUserName/myRepo.git
git clone git@github.com:myUserName/myRepo.git