You are probably here because you are getting frustrated by the error you are getting from your SSH client.
Earlier today, I was in your shoes. I needed to copy the Redis Enterprise Software package from my local computer to an Ubuntu-based AWS EC2 instance.
Here is the command that uses the
scp (Secure Copy) package to copy your file over the internet securely.
💡Most Unix-based machines, such as macOS, and Ubuntu, already have
scp installed. In Windows, you must download an SSH client that supports
scp such as PuTTY. (To learn more about the secure connection, click here).
To my surprise, the command returned this error.
[email protected]: Permission denied (publickey). lost connectionCode language: HTTP (http)
Here are the usual suspects you should control to fix the Permission denied (publickey) ERROR.
Make sure your .pem file has the needed permissions
Enter the command below in your terminal to make your private key file visible enough.
chmod 600 igor-jov-a-a.pemCode language: CSS (css)
Control if your .pem file has the right path
I have changed the directory to the folder that contains my .pem file. That is why my path of the .pem file looks like this.
"igor-jov-a-a.pem"Code language: JSON / JSON with Comments (json)
If you are using a mac and your .pem file is in the /Downloads directory, you can easily change the directory by using this code.
cd /Users/<YOUR_MAC_USERNAME>/DownloadsCode language: HTML, XML (xml)
See if the remote server has the right username & IP
In my case, this is the remote AWS EC2 instance
If you break it down, you will see several factors.
ec2-ubuntu - Username @172.31.0.194 - The IP address of the machine :/tmp - The directory where I want to copy the file toCode language: CSS (css)
Control each of these carefully. In my case, this was the catch. My username was
ubuntu rather than
Nevertheless, the machine will give you the Permission denied (publickey) ERROR even though your .pem file is 100% correct (but in this case, it is created for a different username).
I wish you an error-free day in the Terminal. Enjoy coding.
P.S. If you want to learn more about AWS, read my AWS For Beginners post here.