简体   繁体   中英

Error while doing mina setup

I am using mina to deploy my rails app. I am using aws with nginx and rvm.

Whenever I do mina setup I get

    Permission denied (publickey).

 !     Command failed.
       Failed with status 1 (255)

Here is my deploy.rb file

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

As you have provided that you currently ssh to your instance using .pem file and as Mina doesn't provide a way to connect to ssh using .pem file (yet). So you can add your public_key of your computer to your instance and enable login via public key, which means you can ssh to your instance without password or .pem file.

To copy your public key to your ec2 instance (for Linux or Mac only):

cat ~/.ssh/id_rsa.pub | ssh -i "fuitter.pem" ubuntu@52.88.43.104 "cat >> .ssh/authorized_keys"

ssh to your ec2 instance and restart ssh service:

sudo service ssh restart

Then try to ssh to your instance without pem file

ssh ubuntu@52.88.43.104

If it works, mina will connect to your instance successfully.

As Long Nguyen stated above , Mina doesn't provide a way to connect to ssh using.pem file (yet). So, we need to add the public_key of our computer to the instance and enable login via public key. That's to say connecting to the instance without a password.

However, I have faced some errors with his steps, so here are mine:

  • Generate an SSH key: ssh-keygen -t rsa -m PEM

  • Check it using: ls -lah ~/.ssh , the output should have id_rsa.pub id_rsa

  • Add it to the authorized_keys in your instance: cat ~/.ssh/id_rsa.pub | sudo ssh -i ~/Downloads/my_key.pem ubuntu@x.xxx.xx.xxx "cat >> ~/.ssh/authorized_keys" cat ~/.ssh/id_rsa.pub | sudo ssh -i ~/Downloads/my_key.pem ubuntu@x.xxx.xx.xxx "cat >> ~/.ssh/authorized_keys"

  • Check whether ssh-ing is permitted by the instance, in /etc/ssh/sshd_config , check that PasswordAuthentication is yes and is not commented. (This should be run on the instance itself)

  • Restart sshd service if you make any changes to this file: service ssh restart # On Ubuntu or service sshd restart # On Centos

  • You can now connect to your instance without anu password like thisL: ssh ubuntu@EC2-Public-IP

  • If you needed to set a passowrd for the instance upon loging, try: sudo passwd ubuntu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM