How To Specify Ssh Keys When Running Shell Command Like Git,Rsync

I have a remote repository which is Git. I want to connect to Git over ssh because there are problems with the firewall rules in our work environment. How can use ssh to connect remotely to Git with specifying ssh keys for this Git operations.

With ssh-agent

1

2

ssh-agent$(ssh-add/home/ismail/ssh_keys/ismail;\

git clonegit@github.com:ibaydan/dev.git)

ssh-agent will create and temprorary environment where tkey is added with ssh-add command into the shell. After environment is completed git operations can be done where git will use current ssh keys to connect remotely with ssh tunnel. Keep in mind the keys will be lost after commands are completed

With Host Configuration

Another way to connect remote Git Repository over ssh is using ssh configuration files to specify IdentityFile like below

1

2

Host github.com

IdentityFile~/.ssh/github_rsa

This will work too. When connecting to github.com specified IdentityFile will be used by ssh.