设置 mina 时出错
Error while doing mina setup
我正在使用 mina 来部署我的 rails 应用程序。我将 aws 与 nginx 和 rvm 一起使用。
每当我做 mina setup
我得到
Permission denied (publickey).
! Command failed.
Failed with status 1 (255)
这是我的 deploy.rb
文件
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
set :user, 'ubuntu'
set :domain, 'domain.com'
set :deploy_to, '/usr/share/nginx/html/project'
set :repository, 'https://mc_cannibal@bitbucket.org/mc_cannibal/fuitter2.git'
set :branch, 'master'
# set :forward_agent, true
# For system-wide RVM install.
# set :rvm_path, '/usr/local/rvm/bin/rvm'
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log']
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# set :forward_agent, true # SSH forward_agent.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .ruby-version or .rbenv-version to your repository.
# invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version@gemset.
invoke :'rvm:use[ruby-1.9.3-p125@default]'
end
# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
queue %[
repo_host=`echo $repo | sed -e 's/.*@//g' -e 's/:.*//g'` &&
repo_port=`echo $repo | grep -o ':[0-9]*' | sed -e 's/://g'` &&
if [ -z "${repo_port}" ]; then repo_port=22; fi &&
ssh-keyscan -p $repo_port -H $repo_host >> ~/.ssh/known_hosts
]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
to :before_hook do
# Put things to run locally before ssh
end
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
to :launch do
queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
end
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - http://nadarei.co/mina
# - http://nadarei.co/mina/tasks
# - http://nadarei.co/mina/settings
# - http://nadarei.co/mina/helpers
正如您提供的那样,您当前使用 .pem
文件通过 ssh 连接到您的实例,并且 Mina 不提供使用 .pem
文件连接到 ssh 的方法(目前)。因此,您可以将计算机的 public_key 添加到您的实例并通过 public 密钥启用登录,这意味着您可以在没有密码或 .pem
文件的情况下通过 ssh 连接到您的实例。
将您的 public 密钥复制到您的 ec2 实例(仅适用于 Linux 或 Mac):
cat ~/.ssh/id_rsa.pub | ssh -i "fuitter.pem" ubuntu@52.88.43.104 "cat >> .ssh/authorized_keys"
ssh 到您的 ec2 实例并重新启动 ssh 服务:
sudo service ssh restart
然后尝试在没有 pem 文件的情况下通过 ssh 连接到您的实例
ssh ubuntu@52.88.43.104
如果成功,mina 将成功连接到您的实例。
与Long Nguyen stated 一样,Mina 不提供使用 .pem 文件连接到 ssh 的方法(目前)。因此,我们需要将我们计算机的 public_key 添加到实例中,并启用通过 public 键登录。也就是无密码连接实例
然而,我在他的步骤中遇到了一些错误,所以这是我的:
生成 SSH 密钥:ssh-keygen -t rsa -m PEM
检查它使用:ls -lah ~/.ssh
,输出应该有id_rsa.pub id_rsa
将其添加到您的实例中的 authorized_keys
:
cat ~/.ssh/id_rsa.pub | sudo ssh -i ~/Downloads/my_key.pem ubuntu@x.xxx.xx.xxx "cat >> ~/.ssh/authorized_keys"
检查实例是否允许ssh-ing,在/etc/ssh/sshd_config
中检查PasswordAuthentication
是否为yes
且未被注释。 (实例本身应该是 运行)
如果对此文件进行任何更改,请重新启动 sshd 服务:
service ssh restart # On Ubuntu
或 service sshd restart # On Centos
您现在可以像这样在没有密码的情况下连接到您的实例L:ssh ubuntu@EC2-Public-IP
如果您需要在登录时为实例设置密码,请尝试:sudo passwd ubuntu
我正在使用 mina 来部署我的 rails 应用程序。我将 aws 与 nginx 和 rvm 一起使用。
每当我做 mina setup
我得到
Permission denied (publickey).
! Command failed.
Failed with status 1 (255)
这是我的 deploy.rb
文件
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
set :user, 'ubuntu'
set :domain, 'domain.com'
set :deploy_to, '/usr/share/nginx/html/project'
set :repository, 'https://mc_cannibal@bitbucket.org/mc_cannibal/fuitter2.git'
set :branch, 'master'
# set :forward_agent, true
# For system-wide RVM install.
# set :rvm_path, '/usr/local/rvm/bin/rvm'
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log']
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# set :forward_agent, true # SSH forward_agent.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .ruby-version or .rbenv-version to your repository.
# invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version@gemset.
invoke :'rvm:use[ruby-1.9.3-p125@default]'
end
# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
queue %[
repo_host=`echo $repo | sed -e 's/.*@//g' -e 's/:.*//g'` &&
repo_port=`echo $repo | grep -o ':[0-9]*' | sed -e 's/://g'` &&
if [ -z "${repo_port}" ]; then repo_port=22; fi &&
ssh-keyscan -p $repo_port -H $repo_host >> ~/.ssh/known_hosts
]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
to :before_hook do
# Put things to run locally before ssh
end
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
to :launch do
queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
end
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - http://nadarei.co/mina
# - http://nadarei.co/mina/tasks
# - http://nadarei.co/mina/settings
# - http://nadarei.co/mina/helpers
正如您提供的那样,您当前使用 .pem
文件通过 ssh 连接到您的实例,并且 Mina 不提供使用 .pem
文件连接到 ssh 的方法(目前)。因此,您可以将计算机的 public_key 添加到您的实例并通过 public 密钥启用登录,这意味着您可以在没有密码或 .pem
文件的情况下通过 ssh 连接到您的实例。
将您的 public 密钥复制到您的 ec2 实例(仅适用于 Linux 或 Mac):
cat ~/.ssh/id_rsa.pub | ssh -i "fuitter.pem" ubuntu@52.88.43.104 "cat >> .ssh/authorized_keys"
ssh 到您的 ec2 实例并重新启动 ssh 服务:
sudo service ssh restart
然后尝试在没有 pem 文件的情况下通过 ssh 连接到您的实例
ssh ubuntu@52.88.43.104
如果成功,mina 将成功连接到您的实例。
与Long Nguyen stated
然而,我在他的步骤中遇到了一些错误,所以这是我的:
生成 SSH 密钥:
ssh-keygen -t rsa -m PEM
检查它使用:
ls -lah ~/.ssh
,输出应该有id_rsa.pub id_rsa
将其添加到您的实例中的
authorized_keys
:cat ~/.ssh/id_rsa.pub | sudo ssh -i ~/Downloads/my_key.pem ubuntu@x.xxx.xx.xxx "cat >> ~/.ssh/authorized_keys"
检查实例是否允许ssh-ing,在
/etc/ssh/sshd_config
中检查PasswordAuthentication
是否为yes
且未被注释。 (实例本身应该是 运行)如果对此文件进行任何更改,请重新启动 sshd 服务:
service ssh restart # On Ubuntu
或service sshd restart # On Centos
您现在可以像这样在没有密码的情况下连接到您的实例L:
ssh ubuntu@EC2-Public-IP
如果您需要在登录时为实例设置密码,请尝试:
sudo passwd ubuntu