Vinzent03 / obsidian-git

Integrate Git version control with automatic backup and other advanced features in Obsidian.md
MIT License
6.85k stars 294 forks source link

Using a custom SSH key #32

Open oppegard opened 3 years ago

oppegard commented 3 years ago

Hi there, and thank you for this great plugin!

I'd like a way to use a specific SSH key with minimal change to the code. The plugin could have a new config to specify the GIT_SSH_COMMAND environment variable and pass it down to the simple-git package. I came across this option after reading https://superuser.com/a/912281.

The simple-git npm README uses this environment variable as an example, so I think it's likely to work: https://github.com/steveukx/git-js#environment-variables

While this sort of config is a bit low-level, it does allow future users to make unforeseen SSH customizations they might need through this environment variable.


The specific problem I'm trying to solve is one of convenience while balancing security: the plugin doesn't work after a reboot until my passphrase-protected SSH key is loaded into ssh-agent. This is solved by generating a passphrase-less SSH key. However, I want to restrict this less-secure SSH key to be valid for just that repo, rather than all my repos. This can be done by adding it as a deploy key to the repo's GitHub config.

I can take a pass at adding support for GIT_SSH_COMMAND and submitting a PR. What do you think?

denolehov commented 3 years ago

this sounds like a great idea!

kiprasmel commented 3 years ago

Another reason why someone'd want this is because I don't want the frequent updates to impact my github contributions graph, and using a deploy key seems to solve the issue (at least it worked this way for git journal -- you can change git config.user.username and config.user.email).

Vinzent03 commented 3 years ago

@oppegard @kiprasmel Is any of you ready to test this feature? Haven't used GIT_SSH_COMMAND before, so I cannot really test it.

zanets commented 3 years ago

GIT_SSH_COMMAND is used to tell git how to invoke ssh. I usually use it to debug login issue

GIT_SSH_COMMAND="ssh -vvv" git push ...

@Vinzent03 @denolehov Since I already add patch about env var, I'd like to take a look on this.

BTW, isn't ssh-config more appropriate for this requirment ? Since #66, large scale modification may be painful.

Vinzent03 commented 3 years ago

Yes you are right. I think using ssh-config is a better idea.

gpetry-wex commented 1 year ago

You can add to additional env vars under config a line for GIT_SSH_COMMAND=ssh -i ~/.ssh/id_rsa_whatever WITHOUT QUOTES

joshxyzhimself commented 1 year ago

Mine worked with IdentitiesOnly.

GIT_SSH_COMMAND=ssh -i /home/user/Documents/example/id_rsa -o 'IdentitiesOnly yes'