Pintaste Pintaste

Configuring Git and GitHub on Ubuntu

1 min read 112 words 阅读中文版

System Environment

  • Ubuntu 22.10 kinetic

Installing Git

# Install git using the apt command
sudo apt update && sudo apt full-upgrade -y
sudo apt install git -y

# Verify the installation
git --version
# Example output
git version 2.25.1

Configuring Git Username and Email

git config --global user.name "Your Username"
git config --global user.email "Your Email Address"

# Verify the configuration
git config --list
# Example output
user.name=Your Username
user.email=Your Email Address
# Ctrl + Z to exit

The configuration is stored in the ~/.gitconfig file.

For more Git configuration, you can use the git config command or manually edit ~/.gitconfig.

Configuring GitHub SSH

Create the necessary directories and files

# Create the .ssh directory
mkdir ~/.ssh

# Set permissions:
chmod 700 ~/.ssh

# Create the authorized_keys file:
touch ~/.ssh/authorized_keys

# Set permissions
chmod 600 ~/.ssh/authorized_keys

First, generate a new SSH key

# The following command will create two files: id_rsa and id_rsa.pub
cd ~/.ssh
ssh-keygen -t rsa -c "youremail@youremail.com"

Log in to your GitHub account and go to Settings → SSH and GPG keys.

Click New SSH key → Title → Copy the content from the id_rsa.pub file into the Key field and save.

Copy the content from the id_rsa.pub file in the directory to the GitHub SSH Key and save.

cat id_rsa.pub

Test the GitHub configuration

ssh -T git@github.com

Successful response message

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

Git Learning Resources

CC BY-NC-SA 4.0 · pintaste

Comments

Giscus comments activate once PUBLIC_GISCUS_* env vars are set.