Tuesday, May 13, 2014

RStudio: Pushing to Github with ssh-authentication

If RStudio prompts you for a username and password every time you try to push your project to Github, open the shell (Git menu: More/Shel...) and do the following:

1) Set username and email (if you did not do that before)
git config --global user.name "your_username"
git config --global user.email "your_email@example.com"

2) Create SSH key
ssh-keygen -t rsa -C "your_email@example.com" 

In RStudio, go to menu Tools / Global options / Git SVN / View public key and copy the key to your Github account setting (Edit profile / SSH keys / Add SSH key).

To check that ssh-authentication works, try to run
ssh -T git@github.com

and you should get something like

Hi your_username! You've successfully authenticated, but GitHub does not provide shell access. 

3) Change remote.origin.url from HTTPS to HTTP 

It might be Windows specific, but after 1)+2) RStudio still asks me for user name and password. After a long Google search, I have found a solution here and that is
git config remote.origin.url git@github.com:your_username/your_project.git

Hip, Hip, Hurrah!



If it was trivial for you, I do apologize. I am still very bad in guessing what could be useful for somebody and what not so much. That is why I have this blog and Github account in the first place.

One example, last year I published a paper in JSPI journal that improves a test for interaction in some very specific 2-way ANOVA situation (just one observation per group). The paper submission was an odyssey, mostly because of me. In one moment I doubted whether to retract the paper or not and I even did not upload the package to CRAN at first, just put it on Github.

Then I discovered that some guys found it and had built their package using it. They presented the results at UseR! 2013 conference. I might have met one of those biologists but I am sure I never mentioned my package to them. Finally, - and this is a bit embarrassing - I received an email from Fernando Tusell that I misspelled his name in one of my functions.

In summary, even if you see your work as non-essential from your perceptive, the others may have different view. Just do your best and share your results. Github is a perfect place for this.


8 comments:

  1. Thanks for the post. I've wanted to get this working on Windows for a while. I kept getting frustrated and would give up every time I tried. Worked like a charm.

    ReplyDelete
  2. After Step 2, I seem to be missing something... In my windows version of RStudio (Version 0.98.507), I don't see an option for view public key (I only see an option to create an RSA Key) and I don't see anywhere where I can edit my Github profile (Edit profile / SSH keys / Add SSH key). Any thoughts on what I might be doing wrong? Thanks!

    ReplyDelete
    Replies
    1. Sorry, you should modify your Github profile directly in the browser: https://github.com/settings/ssh

      I do not understand why you do not see link to the public key but there are other ways to get it. See Step 3 at https://help.github.com/articles/generating-ssh-keys

      Delete
    2. Thanks for the clarification. Now that I was able to add the public key to Github, I am able to view the public key in RStudio. I think the issue is that after Step 2 I thought I was supposed to do something in RStudio instead of having to do it on Github. I think things are working now. Thanks! I never would have gotten through this myself... Like Tyler, I've always gotten frustrated and given up!

      Delete
  3. This post is also a great help to me ! many thanks!

    ReplyDelete
  4. Thanks for the tips, I'm happy not to keep having to input my user name and password for every commit

    ReplyDelete