SSH and GPG keys section in Github settingsĮach public key in this list grants the corresponding private key access to your repositories.īack in your terminal, type the following: # Print the public key's fingerprint In the right pane, you'll see a list of SSH keys associated with your account. Find the "SSH and GPG keys" section on the left side and click on it. Go to, click on your avatar and then "Settings". Lastly, let's verify that the correct public key is added to your Github account. Make sure the file has the correct permissions with the following command: # Restrict write & read access to the file owner chmod 600 ~/.ssh/config Verify that the correct public key is attached to your Github account □ Or you can add a ~/.ssh/config file with the following contents: Host # Authenticate with a specific key while cloning a repository GIT_SSH_COMMAND = 'ssh -i /path/to/private_key -o IdentitiesOnly=yes' git clone /. Let SSH know where to find your private key.Rename and place the key in the default location ~/.ssh/id_rsa so SSH can find it.In case you do have a key pair on the system but the SSH client cannot find it, because it's in a different location or has a different name, you have two options: I recommend the latter for better security. You can either copy an existing private key from your local machine or create a new SSH key pair on the remote server. If you're trying to clone a repository from a fresh new VPS, most likely there's no private key present on the server. Github has a good guide on how to generate an SSH key pair. If you don't have a key pair, you can generate one fairly simple. As you can see, SSH was able to find my private key at /Users/maxim/.ssh/id_rsa and will use it to authenticate with Github. The -1 at the end of each line stands for not found. In my case, the debug output looks as follows: debug1: Connecting to port 22.ĭebug1: identity file /Users/maxim/.ssh/id_rsa type 0ĭebug1: identity file /Users/maxim/.ssh/id_rsa-cert type -1ĭebug1: identity file /Users/maxim/.ssh/id_dsa type -1ĭebug1: identity file /Users/maxim/.ssh/id_dsa-cert type -1ĭebug1: identity file /Users/maxim/.ssh/id_ecdsa type -1ĭebug1: identity file /Users/maxim/.ssh/id_ecdsa-cert type -1ĭebug1: identity file /Users/maxim/.ssh/id_ed25519 type -1ĭebug1: identity file /Users/maxim/.ssh/id_ed25519-cert type -1ĭebug1: identity file /Users/maxim/.ssh/id_xmss type -1ĭebug1: identity file /Users/maxim/.ssh/id_xmss-cert type -1 This is the SSH client trying to find a private key by going through a list of possible filenames. Look out for a sequence of lines starting with debug1: identity file. Therefore, to debug your SSH connection with Github, you would type: # Debug the SSH connection to ssh -v will print out a few things to the terminal. To debug an SSH connection you can pass the -v flag to the SSH command. Next troubleshooting step is to check whether the SSH client can find a private key to authenticate with Github. You can view a repository's remotes with: # View a repository's remote list git remote -v Make sure you have a key pair and that the SSH client is using it □ In case you're trying to push to Github, make sure the remote is spelled correctly and pointing to the right repository. Screenshot of Github repository page showing copy command button You can do this by navigating to the repository page and look for a green button labelled "Code" in the upper right corner. I recommend copying the repository location from the Github website to avoid making manual mistakes. The correct format for cloning a Github repository using SSH is: # Syntax for cloning a Github repository using SSH git clone /. It's easy to omit or misspell a letter without you noticing. If you're cloning a repository, double-check you didn't make any typos in the command. Avoid typos by copying the repository location □ However, using root is generally considered insecure and it's better to create a non-root user and disable root login altogether. If you're on a VPS and logged in as root, using sudo doesn't make a difference so this is probably not the reason for the error. This leads to Github denying access to your private repositories because it can't verify that it's you. When you generate SSH keys without sudo and then use sudo to clone a repository, you won't be using the same keys you generated. When you use sudo, you're running the command as the root user and SSH will use a different key pair to authenticate with Github. First of all, try not to use sudo command with git.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |