Configurations
Global Configurations
Global git configurations are done with the flag --global
.
Username and Email
If in <user-name>
you need a spaced name, make sure to wrap it in double quotes. ("User Name"
)
git config --global user.name <user-name>
git config --global user.email <user-email>
Keep in mind that global user configurations do not stop you from impersonating someone else.
Always configure your GPG Signatures, that will be used in Commits, PRs, etc..
Signinkey
Always configure Git to sign Commits, PRs, etc with your GPG Public key.
To configure the Public GPG key for Git to use for its commands.
This key will be used to verfify that Git username is the one from GitHub.
# Speficy the Private key Git will use
git config --global user.signingKey <private-key-ID>
# Make Git use the signinkey in Commits, Tags, etc
git config --global commit.gpgSign true
git config --global tag.gpgSign true
# Make Git sign pushes only if Server supports it
git config --global push.gpgSign "if-asked"
Aside from this configuration you will need to also configure a System Environment Variable.
Don't create a .bash_profile
as it will stop the .bashrc
one from being executed from WSL2, when starting terminals.
$ vim ~/.bashrc
# Add this line to the file
export GPG_TTY=$(tty)
If it works, your signed commits, etc will ask for your Private Key's Password.
Editor to use
To change the default editor that git uses for its commands.
git config --global core.editor "subl -n -w"~
Using GPG Signatures
You should use GPG keys to sign your commits, PRs, and more.
This is a more secure way to verify that action you make are your own so that others cannot impersonate you.
Using VSCode in WSL2
Failure to complete this step will produce errors and failure in using the GPG keys, if using VSCode's to Commit, Push, etc.
Install
GPG4Win
on the Windows side.Then inside Ubuntu make sure GPG is installed
sudo apt-get install gpg gnupg gpg-agent
Edit/create this file in Ubuntu:
# These will cache the passphrase for ~400 days or until computer is restarted
default-cache-ttl 34560000
max-cache-ttl 34560000
# This explicitly tells GnuPG to use the pin entry app on Windows to prompt for the passphrase
pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"
Force restart the gpg agent to apply the changes.
gpgconf --kill gpg-agent
Make sure to add in VSCode.
"git.enableCommitSigning": true
Check existent Keys
Run the command on your machine that you will be using git.
If the command returns nothing, means that there are no generated keys on your system. (If the
/.gnupg
folder doesn't exist it might say that it was created)
gpg --list-secret-key --keyid-form LONG
Create a Private Key
gpg --full-generate-key
Run the command and pick the default key (RSA and RSA).
Choose the key size to be the longest (4096 bits).
The validity time can be any you want.
In user ID to identify your key section
"Real Name" is the same
user.name
you configured in Git. (Which can be your GitHub username or your full name)"Email Address" will also be the same
user.email
configured in Git.
For last, it will request a password so that you can access your keys. (If running on WSL the password window should be opening from Windows)
Get Private Key ID
To find the <private-key-ID>
run the command to show existing keys:
$ gpg --list-secret-key --keyid-form LONG
gpg: checking the trustdb
gpg: marginals needed: 0 completes needed: 0 trust model: pgp
gpg: depth: 0 valid: 0 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
/home/user/.gnupg/pubring.kbx
-----------------------------
sec rsa4096/<private-key-ID> 2024-01-01 [SC] [expires: 2025-01-01]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
uid [ultimate] <User.name> <User.email>
ssb rsa4096/<???> 2024-01-01 [E] [expires: 2025-01-01]
The <private-key-ID>
will be the one after sec rsa4096/
.
Get the Public Key
gpg --armor --export <private-key-ID>
Add Public Key to GitHub
Copy the "Public Key Block" from the first command to GitHub at https://github.com/settings/gpg/new.
Last updated