How to Connect to a Git Remote Server with SSH KEY + Passphrase and Different Port Via Script

Viewed 767

i have a Webserver listening to SSH on Port 1234 . The Webserver uses a public key in ~/.ssh/authorized-keys For authorisation. To connect via SSH i have an private SSH Key with passphrase On my local machine

now i want this Server to be a git Remote Server, so on the Server i create a bare repo in my home directory with a nonRootUser.

mkdir ~/project.git
cd ~/project.git
git init --bare

Now on my local machinei create a new repo

mkdir myProject
cd myProject
git init
git add .
git commit -m "Initial commit"

FROM A SCRIPT i want to set the remote to the Webserver and push to it. And here is where i Stuck

git remote add origin ssh://nonRootUser@WebserverDomain.com:1234/home/project.git
git push origin master

this Produces the Error

Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

I think i still need to add the passphrase, but dont know how. And the Error still lets open if i'm close to an solution or not because it says make sure the repo exists. Thanks in advance

1 Answers

Start an SSH agent, or add the key to your existing agent with the following command:

ssh-add /path/to/your/key

You'll be prompted for the key's passphrase, and it'll be automatically offered for use during SSH authentication.

This article has a decent explanation of what the agent is and what it does, as well as some of the caveats of using one.

https://smallstep.com/blog/ssh-agent-explained/

Related