'Can't SCP to AWS EC2
I have an EC2 instance that I can ping from my Mac but can't SCP
Using below command
scp file.txt ubuntu@<PUBLIC_IP_EC2_INSTANCE>:DESTINATION_DIR
I get error
ubuntu@<PUBLIC_IP_EC2_INSTANCE>: Permission denied (publickey).
lost connection
I followed Sunsetquest's answers in this post but doesn't help.
Solution 1:[1]
Had same issue and it is clearly fault of:
- Wrong private key (or wrong public-private keypair)
- Wrong password for private key
Before trying to scp, try ssh to server, as mentioned in one of comments - if you have set password for key, you will be asked to provide it:
ssh -i /path/to/private/key username@ip_address
If that won't work, then You need to check if public key set on EC2 under directory $HOME/.ssh/authorized_key is proper one for private key used to login. It should look like that:
ssh-rsa public_key_string username@hostname
If that still won't help (and you have set password for keypair), then make sure that password for keypair used when login is the right one.
Solution 2:[2]
The problem is having the wrong permissions on the file.
Execute:
chmod 400 my_pem.pem
From the docs:
Your key file must not be publicly viewable for SSH to work. Use this command if needed: chmod 400 mykey.pem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rickenbacker |
| Solution 2 | Chris Pollard |
