24

I have an account on an ssh-friendly lab machine where I store a lot of private projects so I can access them from multiple computers (and it allows me to only use my few private Github repos for things multiple people will work on).

It seems like Rust is well-equipped to fetch local and public data by using things like

[dependencies.foo]
git = "https://github.com/bar/foo"

[dependencies.baz]
path = "/path/to/baz"

But I haven't found a way to get it to work using ssh git (e.g. git = "git@github.com:bar/foo", or in my case labmachine:bar/foo). I have passwordless/keygen ssh set up, if that helps.

It's not a big deal if it doesn't exist. At the moment I'm just manually cloning the repository and using path = ../foo, which works as long as I keep my directory structure the same and remember to manually pull all dependencies on all my machines. However, it would make things a lot easier if I could just set up Cargo to do it, especially if I just need to quickly demo something on my laptop or whatever.

Linear
  • 21,074
  • 4
  • 59
  • 70
  • I wouldn't think cargo comes with some sort of tool for authenticating git, as the idea of cargo is to grab public dependencies for a one-for-all build tool. – Syntactic Fructose Jul 29 '15 at 15:48
  • I would fully expect that if `git clone foo` works, then `git = "foo"` will work. It should use the same keys, as far as I’m aware. What actually happens? – Chris Morgan Jul 29 '15 at 20:45
  • @ChrisMorgan if you try to use ssh syntax (e.g. git@github just for example) you get "invalid url `git@github.com:my/crate`: relative URL without a base" – Linear Jul 29 '15 at 22:30
  • I really need a solution to this. I have several private repositories on Github and need to share crates between them. `git = "https://github.com/fred/bill"` doesn't work, neither does `git = "git@..."`, nor does `git = "ssh://..."`. `git clone ...` works fine. The complaints are all about authentication. It seems to be ignoring the `git config` user settings. – Steve Powell Mar 23 '17 at 15:24
  • Did you ever figure this out? the labmachine:bar/foo scenario? – cloudsurfin May 01 '20 at 03:50

2 Answers2

13

On macOS Sierra, I had to create a .ssh/config file like this:

Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/id_rsa

with the private key (RSA) file pointed to, and then issue the command:

ssh-add -K ~/.ssh/id_rsa

which (finally!) allowed an entry like:

git = "ssh://git@github.com/skipjaq/loda.git"

to work perfectly.

I do not know how often I will have to repeat the ssh-add command, but it appears this ought to hold at least until the next reboot.

This anomaly is apparently a feature of ssh-agent on macOS Sierra.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Steve Powell
  • 25,354
  • 8
  • 41
  • 44
4

Use a full SSH path rather than Git’s shorthand:

git = "ssh://landmachine/bar/foo"
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
  • 2
    Hmm, not working. If I use my alias defined in in `~/.ssh/config` I get "no such known host". Entering the full url gives `error authenticating: failed connecting agent`. I checked that the full ssh path works with `git clone`, to be clear. – Linear Jul 30 '15 at 21:06
  • That’s troublesome. I’m not sure what’s going on, then. – Chris Morgan Jul 30 '15 at 21:32