Pull from github without authentication every time
Asked Answered
S

5

23

Is there a way to generate a certificate or such so that my prod server can pull from my github repo without me authenticating every single time?

Saddlebag answered 31/10, 2013 at 8:54 Comment(0)
B
15

This is what Deploy Keys are for.

That help article explains what deployment authentication methods GitHub supports and gives some pointers to help decide between them.

In my limited experience, deployment SSH keys are probably the simplest to set up.

Bristle answered 31/10, 2013 at 9:21 Comment(0)
B
42

You can create an access token and use it as username (without password).

Once you have your access token clone the repository:

git clone https://<your-access-token>@github.com/username/repo.git

Then you can pull without authenticating every single time.

This is the simplest method but will store the token plain text into .git/config To improve security you can setup password caching and clone as usual https:

git clone https://github.com/username/repo.git

If you want remove access of server to repository, just delete the access token in your application settings.

I also prefer to use https than ssh on deploy environments. Some times we don't have enough access privileges to handle with ssh, but https access to github is available even on cheaper hosting services.

Bravura answered 31/10, 2013 at 10:54 Comment(3)
This should be the accepted answer. this more robust and can be used for deployment system.Otology
I think this has to be git clone https://<your-user-name>:<your-access-token>@github.com/username/repo.git if your user name is not the same as the repos.Defiance
Works for me with git clone https://<your-access-token>@github.com/username/repo.git on private repository as well. Looks like the user is not required.Bravura
B
15

This is what Deploy Keys are for.

That help article explains what deployment authentication methods GitHub supports and gives some pointers to help decide between them.

In my limited experience, deployment SSH keys are probably the simplest to set up.

Bristle answered 31/10, 2013 at 9:21 Comment(0)
G
15

generate ssh key

cd ~/.ssh 
ssh-keygen -t rsa -C "your-email-address"
touch config

paste in config

 Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/YOUR_KEY

paste public key to github deployment key settings

cat YOUR_KEY.pub

set remote from http to ssh

git remote set-url origin ssh://[email protected]/USERNAME/REPOSITORY.git
Gamez answered 10/10, 2017 at 18:49 Comment(2)
The set-url origin ssh was the missing part on my side. Thanks.Slake
The config part was what I needed, thanks!Snaky
G
2

I think this can be done by using credential caching and using the .netrc file. Please Check This

Gemmulation answered 31/10, 2013 at 8:59 Comment(0)
D
0

Instead of having to clone a repository if the repository is already in place it's simple as:

git remote set-url origin https://<githubToken>@github.com/<github user name>/<repository name>
Dato answered 26/4 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.