Using the Secure Shell (SSH) protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to Version Control Account (BitBucket/GitHub..) accounts without supplying your username or password at each visit.We need to generate SSH key pair, Add the private key to ssh agent and public key to Version control account.
1. Generating SSH key pair
Open Terminal and paste the text below, substituting in your email address or some unique key like employee Id.-
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a new ssh key, using the provided email as a label.
This generates public/private rsa key pair. - When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
2. Adding your SSH key to the ssh-agent
- Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
- If you're using macOS Sierra 10.12.2 or later, you will need to modify your
~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain.Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa
- We have to create the config file and add above mentioned settings in config file.
To create file we can use following command - vim ~/.ssh/config
- Save and exit using following command
:wq - Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
ssh-add -K ~/.ssh/id_rsa
- The -K option is Apple's standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent
At the prompt, type a secure passphrase.3. Adding a new SSH key to your account
We need to add the public key to our version manager (GitHub/BitBucket..) account.
We can find the option to Add SSH Key in Account Setting. - To directly copy the Public key to paste board use following command
pbcopy < ~/.ssh/id_rsa.pub
- Or we can always manually copy the contents of file id_rsa.pub which is present in following path
- Macintosh HD ▸ Users ▸ USER_XXX ▸ .ssh ▸ id_rsa.pub
- With this you should be able to perform all the Git operations from terminal/sourcetree.
source: https://help.github.com/articles/connecting-to-github-with-ssh/
Comments
Post a Comment