Skip to content
Lab Manual
Esc
  • Type at least two characters.
Browse Lab Manual

History: Git Login via SSH

Import from Docusaurus (labmanual/Git/login-via-ssh.mdx) (first version)

Back to history
Added: # Git Login via SSH
Added:
Added: Follow these steps to authenticate Git using SSH.
Added:
Added: ## 1. Check for Existing SSH Keys
Added:
Added: Check if an SSH key already exists:
Added:
Added: ```bash
Added: ls -al ~/.ssh
Added: ```
Added:
Added: If files like `id_rsa` and `id_rsa.pub` are present, you already have a key.
Added:
Added: ## 2. Generate a New SSH Key (If Needed)
Added:
Added: Generate a new SSH key:
Added:
Added: ```bash
Added: ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Added: ```
Added:
Added: Press **Enter** to save it in the default location and set an optional passphrase.
Added:
Added: ## 3. Start SSH Agent and Add Your Key
Added:
Added: Ensure the SSH agent is running:
Added:
Added: ```bash
Added: eval "$(ssh-agent -s)"
Added: ```
Added:
Added: Add your key:
Added:
Added: ```bash
Added: ssh-add ~/.ssh/id_rsa
Added: ```
Added:
Added: ## 4. Copy SSH Key to Git Provider
Added:
Added: Copy the public key:
Added:
Added: ```bash
Added: cat ~/.ssh/id_rsa.pub
Added: ```
Added:
Added: Go to **GitHub/GitLab/Bitbucket** → **SSH and GPG keys** → **New SSH Key**, then paste the copied key.
Added:
Added: ## 5. Test SSH Connection
Added:
Added: Test your connection:
Added:
Added: ### GitHub:
Added:
Added: ```bash
Added: ssh -T git@github.com
Added: ```
Added:
Added: ### GitLab:
Added:
Added: ```bash
Added: ssh -T git@gitlab.com
Added: ```
Added:
Added: ### Bitbucket:
Added:
Added: ```bash
Added: ssh -T git@bitbucket.org
Added: ```
Added:
Added: A successful connection returns a message like:
Added:
Added: ```
Added: Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
Added: ```
Added:
Added: ## 6. Configure Git User Information
Added:
Added: Set your Git username and email:
Added:
Added: ```bash
Added: git config --global user.name "Your Name"
Added: ```
Added:
Added: ```bash
Added: git config --global user.email "your_email@example.com"
Added: ```
Added:
Added: ## 7. Clone a Repository Using SSH
Added:
Added: If cloning a new repository, use:
Added:
Added: ```bash
Added: git clone git@github.com:your-username/your-repo.git
Added: ```
Added:
Added: After completing these steps, you can use Git via SSH without entering your password every time. 🚀