In this woalk through I am going to use GitHub. However, the steps are similar to a Bitbucket profile.
Logged in to your GitHub account, click your profile icon, located (at the time of this writing) on the top right corner.
Select Settings Click SSH and GPG Keys Click Add New SHH Key
A new page will open requiring
- Title
- Key
Type a title that represents the project you are working on.
Open your terminal application and enter the command
ls -al ~/.ssh
The period before the name is telling us, this is a hidden directory. There are two possibilities:
1. You get a list of files, one of these files has the extension .pub
When I execute this command, the response is:
drwx------@ 6 {name} staff 192 3 Mar 14:40 .
drwxr-xr-x+ 60 {name} staff 1920 17 Mar 18:43 ..
-rw-------@ 1 {name} staff 1766 29 Mar 2014 id_rsa
-rw-r--r--@ 1 {name} staff 407 29 Mar 2014 id_rsa.pub
drwxr-xr-x@ 2 {name} staff 64 29 Mar 2014 key_backup
-rw-r--r--@ 1 {name} staff 7312 15 Jan 2021 known_hosts
2. You get the message "File or directory not found"
The file with the .pub extension is the public key of your system. If this file doesn't exist, you'll have to create one. If you do see the file, you can jump to 'continue for all'.
Type: ssh-keygen -t rsa -C "my_email@my_domain.com"
Press Enter to select the default directory where the key is going to be stored (.ssh).
Enter the same passphrase twice (You can leave this empty by pressing Enter twice.)
The system will notify you about the location of your public key and its fingerprint.
Continue for all
Open the file .ssh/id_rsa.pub with vim or your preferred code editor
Copy the whole text, including your email address
Open your browser and paste it into the text area
Click Add SSH key
Or using more detailed instructions:
In your terminal window, copy the contents of your public key file.
On Linux, you can cat the contents:
cat ~/.ssh/id_rsa.pub
On macOS, the following command copies the output to the clipboard:
pbcopy < ~/.ssh/id_rsa.pub
Or use
cat ~/.ssh/id_rsa.pub | pbcopy
From GitHub or Bitbucket, click Add key. You will need to enter a label for your new key, by way of example could be 'default public key'. Paste the copied public key into the SSH Key field.
If you see an email address on the last line when you paste, no stress as it won't matter whether or not you include the email address.
Click Save
Bitbucket sends you an email to confirm the addition of the key.
Go back to your terminal window and verify your configuration and username by entering the following command:
ssh -T git@bitbucket.org
The response message tells you which of your Bitbucket accounts can log in with that key. So you should see something like
authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled
Your local machine can now connect to GitHub.