SSH with version control system
SSH with version control system (Github, bitbucket, etc)
To live in hearts we leave behind is not to die
Run SSH in your machine.
sudo systemctl start sshd
Run SSH in machine startup, so that you do not have to do the above command again in future.
sudo systemctl enable sshd
» Created symlink '/etc/systemd/system/multi-user.target.wants/sshd.service' → '/usr/lib/systemd/system/sshd.service'.
Create a unique key to connect with github/bitbucket, so that anytime you pull or push code from it won’t as you for password. Bitbucket will identify and authorize based on the key.
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_bitbucket
» Will prompt you to enter a passphrase twice. [You can use your pc login password ;-) ]
Re-check to be extra sure that SSH is running.
eval "$(ssh-agent -s)"
» Agent pid 7660 give you something like this. This output means the SSH service is running in your machine.
Now add the newly create key into SSH database.
ssh-add ~/.ssh/id_ed25519_bitbucket
» It will again ask for passphrase you entered earlier.
Let check all the key have
ls -al ~/.ssh
Now we have to give the (.pub) public copy of the key to github/bitbucket.
To avoid running ssh-add for every new session, we can run the following command once and the keychain will store the passphrase and reload that in every session automatically.
# install keychain if it does not exist in you machine
eval $(keychain --quiet --eval ~/.ssh/id_ed25519_bitbucket)
For bitbucket:
Click the setting (cog icon) on the top right next to profile icon > Personal bitbucket settings > SSH keys
Now click add key, on the form give a name and
cat ~/.ssh/id_ed25519_bitbucket.pub
copy the output and paste SSH public key field, and click Save.
That’s it. You can now pull and push new code anytime without typing bitbucket password.
For github:
Visit https://github.com/settings/profile > SSH and GPG keys > New SSH keys >
Now click add key, on the form give a name and
cat ~/.ssh/id_ed25519_bitbucket.pub
copy the output and paste SSH public key field, and click Save.
That’s it. You can now pull and push new code anytime without typing github password.
Now to read the correct public SSH key
Add the following configuration in .ssh/config file
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_ed25519_bitbucket
IdentitiesOnly yes
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
IdentityAgent $SSH_AUTH_SOCK
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal_github
IdentitiesOnly yes
IdentityAgent $SSH_AUTH_SOCK
To load the correct configuration at run time, we have to change the URL while we do cloning.
Example:
For office account: git clone git@github.com:username/repo.git
For personal account: git clone git@github-personal:username/repo.git
