title: Can SSH into server but not git push
body: <p>I am unable to push to my remote git repo stored on my Amazon ec2 instance.</p>
  
  <p>My local <code>ssh</code> <code>config</code> file has a host entry that looks like this:</p>
  
  <pre><code>Host ec2
      HostName ec2-54-89-205-210.compute-1.amazonaws.com
      User ec2-user
      IdentityFile ~/.ssh/ec2TestB
  </code></pre>
  
  <p>And so I can run the command <code>ssh ec2</code> and I will successfully connect to the <code>ec2</code>.</p>
  
  <p>Next, I created a <code>git repo</code> on the <code>ec2</code> in the <code>root</code> folder called <code>testGitRoot</code>.  On my local machine I created a <code>git repo</code> called <code>testGitLocal</code>.  I then add the <code>ec2</code> <code>repo</code> with <code>git remote add origin ec2user@ec2-54-89-205-210.compute-1.amazonaws.com:/root/testGitRoot</code> (I've also tried it without the <code>ec2user@</code> part.. not sure if that is needed).</p>
  
  <p>Bit when I run <code>git push origin master</code> I get:</p>
  
  <pre><code>Permission denied (publickey).
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  </code></pre>
  
  <p>So my question is what concepts am I missing here?  If I'm able to connect over ssh with <code>ssh ec2</code>, then why can't I push my repo?  One thing that isn't clear to me is how exactly the git setup steps I took even utilize <code>ssh</code>.  Normally, I'm always pushing to github, in which case I take the <code>ssh</code> url and set that as my remote.  In this case I'm just setting my <code>ec2</code> <code>repo</code> as remote where that url is just <code>ec2Domain:path/to/git/repo</code>. So I'm not sure even <em>if</em> the <code>git push origin master</code> is using <code>ssh</code>, and if it is, why is it seeming to fail over the public key when the <code>ssh ec2</code> command doesn't??</p>