How to Git Push With SSH Key

Ariadne Lv13

This tutorial describes the process of pushing Git files with specific SSH keys to remote servers using command line.

Introduction

When you have multiple SSH keys and you want to push your Git files to a remote server using a specific SSH key, you can use the following process to do so.

Prerequisites

  1. Git installed on your system.
  2. SSH keys generated and added to your Git account.
  3. A remote server to push your Git files.
  4. A terminal to run the commands.
  5. A Git repository to push your files.
  6. A text editor to edit the SSH configuration file.
  7. A basic understanding of Git and SSH.

Steps to Git Push With SSH Key

  1. Open the terminal on your system.
  2. Navigate to the directory where your Git repository is located.
  3. Run the following command to check the remote URL of your Git repository.
1
git remote -v
  1. Run the following command to check the list of SSH keys on your system.
1
ls -al ~/.ssh
  1. Run the following command to check the list of SSH keys added to your SSH agent.
1
ssh-add -l
  1. Run the following command to check the list of SSH keys added to your Git account.
1
ssh -T
  1. Run the following command to edit the SSH configuration file.
1
nano ~/.ssh/config
  1. Add the following lines to the SSH configuration file.
1
2
3
4
5
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
  1. Replace github.com with the remote server URL and id_rsa with the name of your SSH key.
  2. Save the changes and exit the text editor.
  3. Run the following command to push your Git files to the remote server.
1
git push

Also read:

  • Title: How to Git Push With SSH Key
  • Author: Ariadne
  • Created at : 2024-05-20 09:03:33
  • Updated at : 2024-05-21 17:06:52
  • Link: https://howto.techidaily.com/How-to-Git-Push-With-SSH-Key/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
How to Git Push With SSH Key