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
Git installed on your system.
SSH keys generated and added to your Git account.
A remote server to push your Git files.
A terminal to run the commands.
A Git repository to push your files.
A text editor to edit the SSH configuration file.
A basic understanding of Git and SSH.
Steps to Git Push With SSH Key
Open the terminal on your system.
Navigate to the directory where your Git repository is located.
Run the following command to check the remote URL of your Git repository.
1
git remote -v
Run the following command to check the list of SSH keys on your system.
1
ls -al ~/.ssh
Run the following command to check the list of SSH keys added to your SSH agent.
1
ssh-add -l
Run the following command to check the list of SSH keys added to your Git account.
1
ssh -T
Run the following command to edit the SSH configuration file.
1
nano ~/.ssh/config
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
Replace github.com with the remote server URL and id_rsa with the name of your SSH key.
Save the changes and exit the text editor.
Run the following command to push your Git files to the remote server.