我有一个正在运行的EC2实例(FreeBSD 9 AMI AMI -8cce3fe5),我可以使用亚马逊创建的密钥文件ssh到它,没有密码提示,没有问题。

但是,当我想要使用scp将一个文件复制到实例中时,我被要求输入密码:

scp somefile.txt -i mykey.pem root@my.ec2.id.amazonaws.com:/

Password:

你知道为什么会发生这种情况/如何预防吗?


当前回答

我的hadoopec2cluster。Pem文件是我本地mac目录中唯一的一个文件,使用SCP -i hadoopec2cluster无法将其SCP到aws。pem hadoopec2cluster。pem ubuntu@serverip: ~。

hadoopec2cluster复制。Pem到hadoopec2cluster_2。Pem,然后SCP -i hadoopec2cluster。pem hadoopec2cluster_2。pem ubuntu@serverip: ~。瞧!

其他回答

测试:

执行如下命令:

sudo shred -u /etc/ssh/*_key /etc/ssh/*_key.pub

然后:

创建ami (ec2的图像)。 从第2步的新ami(图像)启动,选择新键。

在您的示例中,根用户不会有任何问题。但在某些情况下,您需要以不同的用户在SSH下登录,请确保您正在scp-ing的目录对您正在SSH-ing的用户具有足够的权限。

将文件从本地服务器复制到远程服务器

sudo scp -i my-pem-file.pem ./source/test.txt ec2-user@1.2.3.4:~/destination/

将文件从远程服务器复制到本地计算机

sudo scp -i my-pem-file.pem ec2-user@1.2.3.4:~/source/of/remote/test.txt ./where/to/put

基本的语法是:-

scp -i my-pem-file.pem username@source:/location/to/file username@destination:/where/to/put

-i是identity_file

对于ec2服务器

#移动你的密钥到/tmp或服务器上的右边文件夹

分配权限

Sudo chmod 600 /tmp/dev-sunrobotics-snippetbucketcom.pem

然后连接到服务器或传输

SCP -i /tmp/dev-snippetbucketcom。Pem filestore.tar.gz ubuntu@85.111.5.33.98:/tmp

确保在您的ip安全,您已经允许ip地址连接

我的hadoopec2cluster。Pem文件是我本地mac目录中唯一的一个文件,使用SCP -i hadoopec2cluster无法将其SCP到aws。pem hadoopec2cluster。pem ubuntu@serverip: ~。

hadoopec2cluster复制。Pem到hadoopec2cluster_2。Pem,然后SCP -i hadoopec2cluster。pem hadoopec2cluster_2。pem ubuntu@serverip: ~。瞧!