试图将 Ansible 剧本从我的本地机器复制到远程主机。但是获得错误的权限

trying to copy an Ansible playbook from my local machine to remote host. But getting bad permissions

我正在尝试将剧本从我的本地机器复制到主机(EC2 实例),但它说我有错误的权限,尽管将我的密钥对添加到 ~/.ssh/id-rsa/ansible-benchmark.pem

Ansible-benchmark.pem 是关键。

我运行的代码是scp /Users/mohammedkhot/Documents/terraform-consul/cis-playbook/main.yaml ec2-18-170-61-4.eu-west-2.compute.amazonaws.com:/etc/ansible

我正在尝试将我的 main.yaml 文件复制到 /etc/ansible/

在尝试复制之前我也做了 运行 chmod 400 但是没有成功。

这是我遇到的错误

@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0755 for '/Users/mohammedkhot/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/mohammedkhot/.ssh/id_rsa": bad permissions
mohammedkhot@ec2-18-170-61-4.eu-west-2.compute.amazonaws.com: Permission denied (publickey).
lost connection```

输出中的第三行告诉您哪里出了问题。您需要对驻留在工作站上的私钥文件有更安全的权限。当前权限过于宽松。

使用 chmod 将您的用户的文件权限更改为只读,然后尝试将文件上传到远程计算机。

$ chmod 600 /Users/mohammedkhot/.ssh/id_rsa
$ scp /Users/mohammedkhot/Documents/terraform-consul/cis-playbook/main.yaml ec2-18-170-61-4.eu-west-2.compute.amazonaws.com:/etc/ansible