Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Differences in git user and repos SSH Keys

As we have a server and we have git repositories hosted in it, frequently we need to git pull and build projects. To pull, we need to have access to the git repository.

The current "logged in” git user in the server is, for example, “x-bot” ( It is part of the team and has access to the repositories the other users do.

Make sure you can login with the x-bot user.

As many deploys are automated, there is no opportunity to type the password, as there is no prompt. To “auto-authenticate” into github, we use a SSH key. It holds an identity and password combination. When you create a key, it is a good idea to keep the same password as in git. In git, not everyone needs to create a SSH key to prevent having to type username / password combination everytime they push or pull. We can assign SSH keys to repositories, so everyone having a copy of the key can push and pull.

The ~/.ssh has many ssh keys and a config file. In it, it's good to have the keys starting with “repo-“ for repository ssh keys and the key starting with “user-“ being an user key (for example, user-x-bot). It's also good to mention names of the repositories in the keys (example: repo-my-labs). It's also good to have the config file in this directory like:

      IdentityFile ~/.ssh/user-x-bot

This key will be used for all other repositories that don’t have their own keys. For example, it will be used to pull a x repository (since this repos does not have a key), but it will not be used for the y repos (since the repo-y key is priority). So they look similar, but having a personal “user” key requires you to have your repository clone under https, and not ssh. And sometimes, requires the operating system’s ssh agent to remember your password. Sometimes this key password can be cleared and you have to re-enter it. Therefore, for automatic deploys it is recommended to use a repo key and clone via ssh.

Do not lose these keys. If that happens, discard these files and re-attach new ssh keys to repositories (only admins have access to do this). Everyone having these files will have to replace them as well.

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