Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EC2 AWS SSH访问权限被拒绝(公钥)_Ssh_Amazon Ec2 - Fatal编程技术网

EC2 AWS SSH访问权限被拒绝(公钥)

EC2 AWS SSH访问权限被拒绝(公钥),ssh,amazon-ec2,Ssh,Amazon Ec2,我正在尝试(使用chef solo和刀子solo)将一个应用程序部署到一个新创建的EC2实例上,正如我在使用Digital Ocean时所做的那样,没有任何问题 ## once the EC2 instance is created and running ## from the console , I setup chef-solo $> knife solo prepare ubuntu@ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com

我正在尝试(使用chef solo和刀子solo)将一个应用程序部署到一个新创建的EC2实例上,正如我在使用Digital Ocean时所做的那样,没有任何问题

## once the EC2 instance is created and running
## from the console , I setup chef-solo

$> knife solo prepare ubuntu@ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com
##  then I run the cookbook
$> knife solo cook ubuntu@ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com

## in this cookbook, I have a recipe to create a 'deploy' group and a user 'myself' in this group
## I also disable root login
##  and I restrict login only to created user
## then other recipes without any problem ( postgres, rbenv, app..)

##  as the user 'myself' is created , I should be able to run ( as w DigitalOcean)

$> ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 yves@ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com

But I get an error : Permission denied (publickey).

为什么不像DigitalOcean那样运行良好,AWS EC2有什么诀窍吗?

用于启动实例的Ubuntu AMI与使用DigitalOcean的AMI不同

in /etc/ssh/sshd_config by default
   PasswordAuthentication no
所以我需要在我的[ssh]配方中添加一个任务

# enable Password Authentication for new user
bash "allow Password Authentication to created user" do
  code <<-EOH
  sed -i '/PasswordAuthentication.*/d' /etc/ssh/sshd_config
  echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
  EOH
notifies :restart, "service[ssh]", :delayed
not_if "grep -xq 'PasswordAuthentication yes' /etc/ssh/sshd_config"
end
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 deployer@ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com