我试图使用我的Mac终端scp一个文件从下载(phpMyAdmin我下载在线)到我的亚马逊EC2实例。

我使用的命令是:

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

我得到的错误是: 警告:身份文件myAmazonKey。pem not accessible:表示没有这样的文件或目录。 权限被拒绝(公钥)。 失去联系

都是我的亚马逊钥匙。pem和phpMyAdmin-3.4.5-all-languages.tar.gz都在下载中,所以我尝试了

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

我得到的错误是: 警告:身份文件/User/Hello_Kitty22/Downloads/myAmazonkey。pem not accessible:表示没有这样的文件或目录。 权限被拒绝(公钥)。 失去联系

有人能告诉我怎么解决我的问题吗?

附注:有一个类似的帖子:SCP(安全副本)到ec2实例,没有密码 但这并没有回答我的问题。


当前回答

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

其他回答

本视频将逐步介绍使用SCP将文件从本地计算机复制到AWS EC2 Linux实例的过程(包括下面提到的要点)。

要使用SCP纠正这个特定问题:

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. 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

我会用:

SCP -i " .pem文件的路径" "从本地机器复制的文件" username@amazoninstance: "远程机器复制文件的目标文件夹"

检查.pem文件的权限…Openssh通常不喜欢世界可读的私钥,并且会失败(iir, SCP在向用户提供这种反馈方面做得不好)。

您可以简单地用该密钥ssh到AWS主机吗?

为了SSH工作,您的密钥必须是不可公开可见的。如果需要使用此命令:

chmod 400 yourPublicKeyFile.pem

尝试将用户指定为ec2-user,例如:

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

参见使用SSH连接Linux/UNIX实例。