Using scp to copy a file to Amazon EC2 instance?

我的未来我决定 提交于 2019-11-29 18:35:09

Try specifying the user to be ec2-user, e.g.

scp -i myAmazonKey.pem phpMyAdmin-3.4.5-all-languages.tar.gz ec2-user@mec2-50-17-16-67.compute-1.amazonaws.com:~/.

See Connecting to Linux/UNIX Instances Using SSH.

second directory is your target destination, don't use server name there. In other words, you don't need to mention machine name for the machine you're currently in.

scp -i /path/to/your/.pemkey -r /copy/from/path user@server:/copy/to/path

-r if it's a directory.

Castelmager

Your key must not be publicly viewable for SSH to work. Use this command if needed:

chmod 400 yourPublicKeyFile.pem

You should be on you local machine to try the above scp command.

On your local machine try:

scp -i ~/Downloads/myAmazonKey.pem ~/Downloads/phpMyAdmin-3.4.5-all-languages.tar.gz  hk22@mec2-50-17-16-67.compute-1.amazonaws.com:~/.

Here are the details of what works for an EC2 instance:

scp -i /path/to/whatever.pem /users/me/path-to-file ec2-user@ec2-55-55-555-555.compute-1.amazonaws.com:~

Few notes for beginning:

  1. Note the spaces between the three parameters given after the -i
  2. scp stands for secure copy protocol. Knowing the words makes it easier to remember the command.
  3. -i dictates that you need to give the .pem file as the next param. If there is no -i, than you do not need a .pem.
  4. Note the :~ at the end of the destination for the EC2 instance.

I had exactly same problem, my solution was to

scp -i /path/pem -r /path/file/ ec2-user@public aws dns name: (leave it blank here)

once you done this part, get into ssh server and mv file to desired location

Prafull
scp -i ~/path to pem file/file.pem -r(for directory) /PATH OF LOCAL/localfile user@hostname:PATH OF SERVER/serverdirectory

Below SCP format works for me

scp -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com:~/SampleFile.txt ~/SampleFile2.txt

SampleFile.txt: It will be the path from your root directory(In my case, /home/ubuntu). in my case the file which I wanted to download was at /var/www

SampleFile2.txt: It will be path of your machine's root path(In my case, /home/MyPCUserName)

So, I have to write below command

scp -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com:~/../../var/www/Filename.zip ~/Downloads

Send file from Local to Server:

scp -i .ssh/awsinstance.pem my_local_file ubuntu@XX.XXX.XXX.XXX:/home/ubuntu

Download file from Server to Local:

scp -i .ssh/awsinstance.pem ubuntu@XX.XXX.XXX.XXX:/home/ubuntu/server_file .

The process of using SCP to copy files from a local machine to an AWS EC2 Linux instance is covered step-by-step (including the points mentioned below) in this video.

To correct this particular issue with using SCP:

  1. You need to specify the correct Linux user. From Amazon:

    • For Amazon Linux, the user name is ec2-user.
    • For RHEL, the user name is ec2-user or root.
    • For Ubuntu, the user name is ubuntu or root.
    • For Centos, the user name is centos.
    • For Fedora, the user name is ec2-user.
    • For SUSE, the user name is ec2-user or root.
    • Otherwise, if ec2-user and root don't work, check with your AMI provider.
  2. Your private key must not be publicly visible. Run the following command so that only the root user can read the file.

    chmod 400 /path/to/yourKeyFile.pem
    

Check the permissions on the .pem file...openssh usually doesn't like world-readable private keys, and will fail (iir, scp doesn't do a great job of providing this feedback to the user).

Can you simply ssh with that key to your AWS host?

First you should change the mode of .pem file from read and write mode to read only mode. This can be done just by a single command in terminal sudo chmod 400 your_public_key.pem

I tried all the suggestions mentioned above and nothing worked. I terminated the current instance, launched another one and repeated the same exact process. This time no problems. Sometimes it might be the remote ami's fault.

user1738344

I would use:

scp -i "path to .pem file" "file to be copeide from local machine" username@amazoninstance: 'destination folder to copy file on remote machine'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!