GIT SSH - gecko-8/devwiki GitHub Wiki
Create an SSH Key
- Navigate to your .ssh folder, creating it if necessary. On Windows this should be under
C:\Users\Jason\.ssh
. On MacOS and Linux this will be a hidden folder at~:/.ssh
. - Execute the following command to create the key.
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- When prompted, set a name however you like.
- When prompted, enter and confirm a passphrase for the key.
Edit .ssh\config File (if key name other than default)
- Enter the following into your
.ssh\config
file (following example is for Github)Host github.com User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/<your key name>
Set File Permission (Linux only)
Fix Permission Handling in WSL (Not needed for general Linux)
- Edit the ~/etc/wsl.conf
- Add the following
[automount] enabled = true root = / options = "metadata" mountFsTab = true
- Restart the instance
Set Permissions
- Execute the commands
chmod 600 <your key name> chmod 600 config
Start the SSH Agent
Default ssh-agent Included With Windows 10
- Open the Windows menu and type "Services"
- Find the OpenSSH Authentication Agent entry
- Right-click it and choose Properties
- Set
Startup Type
toAutomatic
- Click Okay
Linux
Should already be running. You can check with the following command
eval "$(ssh-agent -s)"
Register the Key
- Open your console
- Navigate to your .ssh folder
- Enter the following command:
For example, if your key name is git_rsa, execute (note no extension)ssh-add <Your key name>
ssh-add git_rsa
- Enter the passphrase when prompted
Autostart Agent and Add Key on Login (Linux)
- Open your ~/.bashrc file.
- Add the following to the end of it (be sure to replace with your key name).
Source: https://stackoverflow.com/questions/18880024/start-ssh-agent-on-login# Load identities SSH_ENV="$HOME/.ssh/agent-environment" function start_agent { echo "Initialising new SSH agent..." /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" echo succeeded chmod 600 "${SSH_ENV}" . "${SSH_ENV}" > /dev/null /usr/bin/ssh-add ~/.ssh/<your SSH key name>; } # Source SSH settings, if applicable if [ -f "${SSH_ENV}" ]; then . "${SSH_ENV}" > /dev/null #ps ${SSH_AGENT_PID} doesn't work under cywgin ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_agent; } else start_agent; fi
- Restart the instance
Register the Key on Your GIT Provider
Github
- Open the Github console
- Open your account settings
- Click
SSH and GPG keys
- Under
SSH keys
click New SSH Key - Enter a name
- In the Key field, copy and paste the contents of your .pub file found in your .ssh folder.
Gitlab
- Open the Gitlab console
- Open your account settings
- Click
SSH Keys
- In the Key field, copy and paste the contents of your .pub file found in your .ssh folder.
- Enter a Title in the title field.
- You can leave the Expires At field empty.
- Click Add Key
AWS CodeCommit
- Sign-in to the AWS console with your user login (don't use the root account for this).
- Navigate to the IAM page.
- Click on Users in the left-hand menu.
- Click on your user entry.
- Select the Security Credentials tab.
- Under SSH Keys for AWS CodeCommit click Upload SSH Public Key.
- Copy and paste the contents of your .pub file found in your .ssh folder.
- Click the Upload SSH Public Key button.