Creating SSH keys for Git server access
To secure your access to your Git server repository, you must create a new SSH key pair to authenticate each user account that you want to grant access to repository data. SSH is a secure protocol for connecting to remote computers using a pair of cryptographic keys.
This topic describes how to:
Note
- This topic assumes that you're hosting your repository on GitHub. If you've instead installed a Git server on a local computer, you must install and configure an SSH server on the host computer to use the SSH protocol for client/server connections. Alternatively, you could configure the server to use other protocols, including HTTP, a file share, or Git's own protocol. For more information, see see Git on the Server - The Protocols.
- Repeat the procedures on this topic on each writers' computer; every user account that accesses the repository should use its own SSH keys.
Creating your keys
The SSH key pair consists of two automatically generated files: a public key file and a private key file.
To create the SSH keys
- Open Git Bash.
Tip On a Windows computer, you can open Git Bash from the Windows Start menu.
- At the prompt, change to your user home directory by entering this command:
cd ~
Tip To show the path of your user home directory, enter the command pwd, which is an acronym for "present working directory."
- At the prompt, enter this command to create a new directory (named .ssh) for your SSH key pair:
mkdir .ssh
- Enter the following command at the prompt, substituting in the email address want to use to connect to your GitHub repository:
ssh-keygen -t ed25519 -C "your_email@example.com"
- Press Enter to save the key in the .ssh folder you created in step 3 and use the default file name (id_ed25519).
- At the prompt, optionally enter a memorable passphrase to secure your account. The passphrase is case-sensitive; and is required each time you push data to the repository. Alternatively, you can press Enter to skip securing your account with a passphrase.
Tip Think of a passphrase as a password consisting of multiple words, that is something only you would know and can easily remember (for example, Birthday Dinner @Antonios Food Poisoned Never Again!).
- If you entered a passphrase in the previous step, then enter the same passphrase again for verification. Otherwise, skip this step.
The SSH key pair is automatically created in the .ssh folder. The pair consists of the generated public key file (id_ed25519.pub) and private key file (id_ed25519).
Important You can freely share the public key, but must keep the private key file safe (in the same way that you would protect a password).
Configuring the keys for use with GitHub
To use the keys with GitHub, let's create a configuration file associating the site's address with the new SSH key you created.
To create the SSH config file
- At the same Git Bash prompt, change directories to the .ssh folder:
cd .ssh
- Create a new SSH config file:
touch config
- Using a text editor (such as notepad), edit the config file you created in the previous step and define the file's contents as follows:
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_ed25519
- Save the file and close the editor.
Adding your public key to GitHub
Now that you've created your key pair, you're ready to add your public key to GitHub.
Important If you're creating keys for a different user account than the one you used to create your GitHub repository, then prior to completing this procedure, you must create a GitHub account using the email address that associated with your SSH key in step 4 of Creating your keys. If your repository is private, then you must also invite this user account to collaborate with your repository. For more information, see Inviting collaborators to a personal repository.
To add your public key to GitHub
- In a browser, navigate to https://github.com/settings/keys.
- Click New SSH key.
- Enter a Title to help you remember this key, such as Your_User_Name@Your_Computer_Name.
- In a text file editor (such as notepad), open the public key id_ed25519.pub that you created earlier, and then copy and paste the contents to the Key box on the GitHub site.
- Click Add SSH key.
Now that you've configured your computer to securely access GitHub, you're ready to clone your project's repository to each writer's computer.