Skip to content

Instantly share code, notes, and snippets.

@yogeek
Last active September 13, 2018 09:48
Show Gist options
  • Save yogeek/3fab8a981ff772b7bb50c37a7040180f to your computer and use it in GitHub Desktop.
Save yogeek/3fab8a981ff772b7bb50c37a7040180f to your computer and use it in GitHub Desktop.
GIT config

Generate GPG key

gpg --full-gen-key

Get key id

gpg --list-secret-keys --keyid-format LONG

/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid                          Hubot 
ssb   4096R/42B317FD4BA89E7A 2016-03-10

GPG_KEY_ID=3AA5C34371567BD2

Add key to github

firefox https://github.com/settings/gpg/new

Configure GIT to use this key to sign commits : Globally

git config --global user.signingkey $GPG_KEY_ID

Configure GIT to use this key to sign commits : Repo-only

cd repo
vim .git/config

################### LOCAL GIT CONFIG ####################
[user]
        name = <name> <first_name>
        email = <email>
        signingkey = 3AA5C34371567BD2
[remote "origin"]
        url = [email protected]:<github_username>/<repo>.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[commit]
        gpgsign = true

To sign-off the last N commits

git filter-branch --msg-filter "cat - && echo && echo 'Signed-off-by: Your Name <[email protected]>'" HEAD~N..HEAD

Generate SSH key (no passphrase)

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -P ""

Add key to github

firefox https://github.com/settings/ssh/new

Configure SSH Host

vim ~/.ssh/config

################### SSH CONFIG ####################
Host github.com-yogeek
	HostName github.com
	User yogeek
	PreferredAuthentications publickey
	IdentityFile ~/.ssh/id_rsa_github

Options in ~/.ssh/config:

Host github-<identify_specific_user> : Host could be any value that could identify a host plus an account, it don't need to be a real host, e.g github-kc identify one of my account on github for my local laptop, When set remote url for a git repo, this is the value to put after git@, that's how a repo maps to a Host, e.g git remote set-url origin git@github-kc:kuchaguangjie/pygtrans.git

[Following are sub options of Host] Hostname : specify the actual hostname, just use github.com for github, User git : the user is always git for github, IdentityFile : specify key to use, just put the path the a public key, LogLevel : specify log level to debug, if any issue, DEBUG3 gives the most detailed info.

Test

ssh -T [email protected]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment