Set up SSH for Git

suggest change

If you are using Windows open Git Bash. If you are using Mac or Linux open your Terminal.

Before you generate an SSH key, you can check to see if you have any existing SSH keys.

List the contents of your ~/.ssh directory:

$ ls -al ~/.ssh 
# Lists all the files in your ~/.ssh directory

Check the directory listing to see if you already have a public SSH key. By default the filenames of the public keys are one of the following:

id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub

If you see an existing public and private key pair listed that you would like to use on your Bitbucket, GitHub (or similar) account you can copy the contents of the id_*.pub file.

If not, you can create a new public and private key pair with the following command:

$ ssh-keygen

Press the Enter or Return key to accept the default location. Enter and re-enter a passphrase when prompted, or leave it empty.

Ensure your SSH key is added to the ssh-agent. Start the ssh-agent in the background if it’s not already running:

$ eval "$(ssh-agent -s)"

Add you SSH key to the ssh-agent. Notice that you’ll need te replace id_rsa in the command with the name of your private key file:

$ ssh-add ~/.ssh/id_rsa

If you want to change the upstream of an existing repository from HTTPS to SSH you can run the following command:

$ git remote set-url origin ssh://git@bitbucket.server.com:7999/projects/your_project.git

In order to clone a new repository over SSH you can run the following command:

$ git clone ssh://git@bitbucket.server.com:7999/projects/your_project.git

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents