# How to specify the SSH key for Pkg to use

**URL:** <https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784>\
**Category:** General Usage\
**Tags:** pkg, github, ssh\
**Created:** [September 10, 2018, 9:11pm UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784 "2018-09-10T21:11:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [September 10, 2018, 9:11pm UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/1 "2018-09-10T21:11:36Z")

</div>

I’m trying to get `Pkg` to use a different SSH key when it instantiates a project. I naively tried this:

```bash
env GIT_SSH_COMMAND='ssh -i /path/to/key' julia --project -e 'using Pkg; Pkg.instantiate()'

```

But it doesn’t seem to work. Is there a different way to do this?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [September 11, 2018, 7:26am UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/2 "2018-09-11T07:26:46Z")

</div>

`Pkg` doesn’t use the `ssh` binary but instead `libssh2` via `libgit2`. `libssh2` doesn’t use the `GIT_SSH_COMMAND` environment variable but instead `SSH_KEY_PATH` for the private key and `SSH_PUB_KEY_PATH` for the public key. Yes, it needs both and yes, it’s annoying. All information is available in the private key and the public key can be extracted from it using `ssh-keygen`, but `libssh2` doesn’t include the necessary crypto support to do it internally.

Edit: Strictly speaking `SSH_KEY_PATH` and `SSH_PUB_KEY_PATH` aren’t used by `libssh2`. Rather it’s Julia’s wrapper of `libgit2` that reads those and passes them on through the internal APIs to libssh2.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [September 11, 2018, 7:37am UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/3 "2018-09-11T07:37:10Z")

</div>

If you’re on Windows you might also run into [https://github.com/JuliaLang/julia/issues/28933](https://github.com/JuliaLang/julia/issues/28933) depending on how your git server is configured.

---

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [September 11, 2018, 8:24pm UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/4 "2018-09-11T20:24:15Z")

</div>

That worked, thank you!

---

<div class="post-metadata">

**Author:** ![Imi\_Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imi_kim/32/9699_2.png) [@Imi\_Kim](https://discourse.julialang.org/u/Imi_Kim)\
**Post date:** [March 24, 2020, 8:48am UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/5 "2020-03-24T08:48:25Z")

</div>

I just tried this (with julia 1.4.0) and it does not work — Defined both env variables, but Pkg keeps asking for the location of the private key (actually guesses it correctly, as it is the default), after three attemps, fails

I have submitted an issue: [Pkg add private repo not using ssh key · Issue #1733 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/1733)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [March 24, 2020, 9:52am UTC](https://discourse.julialang.org/t/how-to-specify-the-ssh-key-for-pkg-to-use/14784/6 "2020-03-24T09:52:21Z")

</div>

If you already have the key in the default location, setting `SSH_KEY_PATH` and `SSH_PUB_KEY_PATH` won’t help. It is unfortunate that it keeps asking for `private key location` when what it really means is that something, anything, went wrong during the authentication, and frequently the location of the key is not at all the problem.

Sadly it’s not that easy to debug this. If you have control of the server end you may be able to enable debug output from the ssh server and possibly make sense of it. If you cannot get information from the server and you are sufficiently desperate you can try [https://github.com/JuliaLang/Pkg.jl/issues/1516#issuecomment-560794389](https://github.com/JuliaLang/Pkg.jl/issues/1516#issuecomment-560794389).
