【发布时间】:2020-09-27 22:16:18
【问题描述】:
我有一个在 Elastic beanstalk 上运行的 Rails 5 应用程序。从我的应用程序中,我想重新启动在另一个 EC2 实例上运行的 docker 容器。
这是我写的部分代码:
system("ssh -i ~/.ssh/<ssh_key> <EC2 instance IP> 'docker restart <container_name>')
我在 ~/.ssh 文件夹中手动将 SSH 密钥添加到我的实例中,并对其运行 chmod 400。在 ssh 进入弹性 beanstalk 之后手动运行此命令时,它是成功的,但是当应用程序运行时,它不会成功重新启动服务器。
我的猜测是问题在于我通过ec2-user 添加了 ssh 密钥,而正在运行的应用程序正在使用另一个用户。如果是这样的话,我怎么能做到这一点?我尝试更改用户并为webapp 用户添加ssh 密钥,但在sudo su webapp 之后显示This account is currently not available.
有没有更好的方法来实现同样的目标?
【问题讨论】:
-
错误日志如下
Warning: Identity file /home/webapp/.ssh/<key> not accessible: No such file or directory. Could not create directory '/home/webapp/.ssh'. Host key verification failed.
标签: ruby-on-rails amazon-web-services docker amazon-ec2