Deploy key is a SSH key set in your repo to grant client read-only (as well as r/w, if you want) access to your repo.
As the name says, its primary function is to be used in the deploy process in replace of username/password, where only read access is needed. Therefore keep the repo safe from the attack, in case the server side is fallen.
-
Generate a ssh key
run
ssh-keygen -t rsa -b 4096 -C "{email}"
, leave the password empty as you want the deploy process keyboard-less.after the generation, file
id_rsa
andid_rsa.pub
can be found under.ssh
folder. -
add ssh key to repo's "Deploy keys" setting
cat .ssh/id_rsa.pub
-
Setup the git ssh key on the client machine
Git normally use the ssh key found in
.ssh/id_rsa
under user's home folder, so first you need to find out the home directory of the user.for example, on Ubuntu/Debian, in default, user
www-data
's home directory is/var/www
, so the ssh key file is/var/www/.ssh/id_rsa
).Then copy the
id_rsa
file from Step 1 to the right directory.You can test the connection by:
sudo -u {user} ssh -T [email protected]
*You might need to grant Github's key to known hosts.
If everything went well, you can see:
Hi {user}! You've successfully authenticated, but GitHub does not provide shell access.
Then you are all set!
Attention: make sure your repo url use git protocol not http, which means use
[email protected]:{user}/{repo}.git
not
https://github.com/{user}/{repo}.git
You can use /.ssh/config
file to config different ssh key for different repo. For detail, please follow the instruction in Ref.3 below.
I don't quite understand what you want to ask here.
deploy keys are just ssh keys. and git can be authenticated through ssh keys. That's the basic idea.
It's called deploy key because it is used, by design, if I understand it correctly, to pull code only, for machines that are in like production environments. Therefore, even if the key is leaked, your repo should be still safe from tempering.
So, if the repo is public, you don't need this kind of authentication to pull code, just,
git pull xxx
.If you already have a private github repo, and want to use deploy key, add pub-key to the repo by Step 2 written above.
Linux user ssh keys are the same, but in login into linux, your linux server has the pub-key, your client has the pri-key. after login, if you need to login into github through ssh protocol, your server should have the pri-key and github have the pub-key. and it is a bad practice that both pri-key and pub-key are on the same machine and used in different scenarios.
I don't know if I answered your question