Skip to main content

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.

Related articles

Andrew Fletcher18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...
Andrew Fletcher12 Mar 2024
How to determine the size of a directory in Terminal
To determine the size of a directory using the terminal, you can use the du (disk usage) command. The syntax for this command can vary slightly depending on the operating system you are using, but a common way to use it is as follows:&nbsp;For Linux and macOSdu -sh /path/to/directoryduDisk...
Andrew Fletcher06 Mar 2024
Terminal command to find and replace
In many terminal text editors, you use find command as reference in Terminal commands - find. &nbsp;How about find and replace. &nbsp;This action depends on the specific text editor you're using in the terminal. &nbsp;Here are a few common terminal text editors and how you can find and replace...