title: Permission denied (publickey) error while copying to EC2
body: <p>I'm trying to copy file from my local to Aws EC1 or EC2.</p>
  
  <p>my detailed setup.</p>
  
  <ol>
  <li><p>Created two EC2 instances.</p></li>
  <li><p>Got .pem file (Private key) from AWS consle.</p></li>
  <li><p>Generated private key from .pem file (step2).</p></li>
  <li><p>Able to connect EC1 and EC2 using private key generated in step 3.</p></li>
  <li><p>Copied .pem file in EC1 and EC2 servers, by doing that am able to copy files in between EC1 and 2 aws servers.</p></li>
  </ol>
  
  <p>Now I want to copy the file from my local machine to AWS EC1 and EC2 serves.</p>
  
  <p>But when am trying to do below command (using public DNS):</p>
  
  <pre><code>ssh ubuntu@ec2-18-222-170-204.us-east-2.compute.amazonaws.com 
  </code></pre>
  
  <p>getting below error </p>
  
  <blockquote>
    <p>Permission denied (publickey)</p>
  </blockquote>
  
  <p>And when I do it using Private DNS:</p>
  
  <pre><code>ssh ubuntu@ip-172-31-43-162.us-east-2.compute.internal
  </code></pre>
  
  <p>getting below error:</p>
  
  <blockquote>
    <p>ssh: Could not resolve hostname ip-172-31-43-162.us-east-2.compute.internal: Name or service not known</p>
  </blockquote>
  
  <p>what should I do to fix this or make it work?</p>
  
  <p>Output</p>
  
  <pre><code>OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g  1 Mar 2016
  debug1: Reading configuration data /etc/ssh/ssh_config
  debug1: /etc/ssh/ssh_config line 19: Applying options for *
  debug2: resolving "ip-172-31-43-162.us-east-2.compute.internal" port 22
  ssh: Could not resolve hostname ip-172-31-43-162.us-east-2.compute.internal: Name or service not known
  </code></pre>