Skip to content

Instantly share code, notes, and snippets.

@JeyDi
Forked from mcandre/git-ssh-access-faq.md
Last active July 12, 2022 15:30
Show Gist options
  • Save JeyDi/032dd160ed60db76971af89578598ca5 to your computer and use it in GitHub Desktop.
Save JeyDi/032dd160ed60db76971af89578598ca5 to your computer and use it in GitHub Desktop.
Git/SSH Access Frequently Asked Questions

Git/SSH Access FAQ

If you see Access denied, or other error messages when trying to access a git repository or SSH server, here are some steps you can take to resolve the problem.

Enable verbose mode

When in doubt, run ssh -vvv <other options...> to enable more verbose logging.

How do I request git repo / ssh permissions?

Ask your GitHub, GitLab, or ssh administrator to grant you permissions. For example, if you mostly work on master in GitLab, you may want Master permissions on the projects you work on.

Administrators

How do I quickly fix SSH keys?

When in doubt, try creating new SSH keys, without password protection, and resubmitting the new public key to GitHub, GitLab, or whichever git or SSH server you are using.

$ rm $HOME/.ssh/id_rsa*
$ ssh-keygen -t rsa -C <your email address>
Enter file in which to save the key ($HOME/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Press enter]
Enter same passphrase again: [Press enter]

Your identification has been saved in $HOME/.ssh/id_rsa.
Your public key has been saved in $HOME/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db <email address>

$ cat $HOME/.ssh/id_rsa.pub

Then copy & paste public key file contents into GitHub/GitLab/etc.'s new ssh key page.

Where do I get help with git / SSH keys?

The git community is very helpful for troubleshooting SSH key problems. Ask and ye shall receive.

IRC

  • irc://irc.freenode.net:6697/#git
  • irc://irc.freenode.net:6697/#github
  • irc://irc.freenode.net:6697/#gitlab
  • irc://irc.freenode.net:6697/#bitbucket
  • irc://irc.freenode.net:6697/#ssh

Reddit

SuperUser

http://superuser.com/search?q=ssh+key

Tutorials

How do I configure SSH keys?

Path User/Owner Group Permissions chmod code
$HOME/.ssh/known_hosts $USER staff -rw-r--r-- 0644
$HOME/.ssh/authorized_keys (on server) $USER staff -rw------- 0600
$HOME/.ssh/id_rsa $USER staff -rw------- 0600
$HOME/.ssh/id_rsa.pub $USER staff -rw-r--r-- 0644
$HOME/.ssh/config $USER staff -r-------- 0400
$HOME/.ssh $USER staff drwx------ 0700
$HOME $USER staff drwxr-xr-x+ 0755
/home (Linux) root admin drwxr-xr-x+ 0755
/Users (Mac OS X) root admin drwxr-xr-x+ 0755
C:\Users (Windows) Administrators - - -

For each of these paths, use sudo ls -Ahl <path>/sudo chmod <code> <path> to observe/enforce the correct file permissions.

  • change group: sudo chgrp <group_name> file
  • change owner: sudo chown <user> file
  • change owner to you directly of a folder (with subfiles): sudo chown -R $(whoami) ./folder
  • change permission to a file: sudo chmod 700 /home/<name>/.ssh

Windows users may substitute %HOME% for $HOME, unless in Git Bash, MSYS, or other cygwin environments.

known_hosts

Sometimes SSH will silently fail when there's a discrepancy between the information in $HOME/.ssh/known_hosts on the client and the IP address / hostname of the server. This can happen, for example, if the server uses DHCP and changes IP addresses. To fix this, delete any related entries in $HOME/.ssh/known_hosts on the client, and consider configuring the server with a static IP address.

How do I configure SSH servers?

Confirm that /etc/ssh/sshd_config is configured with PubkeyAuthentication yes. If necessary, restart the ssh service with service ssh restart or /etc/init.d/ssh restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment