How to prevent Capistrano from displaying password when deploying - ruby-on-rails

I recently started deploying my rails apps using Capistrano, but I can't seem to figure out how to not display my password when deploying the app when it prompts me for my password.
I get the following warning,
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
I installed both of those gems, and my password is still being echoed in clear text. Any help would greatly be appreciated.

Add this in config/deploy/production.rb
set :ssh_options, {
keys: %w(/Users/artemadamcov/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey password),
port: 4321
}
And enter it in terminal
ssh-add ~/.ssh/id_rsa

Related

Capistrano: no tty present and no askpass program specified

I'm trying to deploy a Rails app with Capistrano to my Ubuntu server.
Having these in my production.rb:
set :pty, false
set :use_sudo, false
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w[~/.ssh/id_ed25519.pub] }
This used to work, but now I'm getting no tty present and no askpass program specified errors. I have also tried changing permissions for my deploying user on the server, giving it ALL permissions. This is happening when it's trying to run: sudo /bin/systemctl restart puma_production
I feel like I have tried every possible combination of settings out there. If I set set :pty, true it will ask for a password but I can't enter it.
What am I missing here?

Capistrano Net::SSH.start deprecating watning

Just upgraded to the latest capistrano and my rails deployments are all printing this warning -
/home/vivek/.rvm/gems/ruby-2.4.1/gems/sshkit-1.14.0/lib/sshkit/backends/connection_pool.rb:59:in `call': Passing nil, or [nil] to Net::SSH.start is deprecated for keys: user
Everything seems to be working.
I upgraded from 3.5.0 to the current release (3.91.). Is there anything that needs to be changed in deploy.rb?
When declaring your servers in e.g. config/deploy/production.rb, make sure to explicitly set a username. My guess is that you don't have one specified, hence the warning.
For example:
server "example.com", user: "deploy", roles: %w[app web]
You can test that the username is being accepted by running:
$ cap production doctor:servers
Servers (1)
deploy#example.com [:app, :web]
The username for each server can also be overridden globally via :ssh_options. If you set :ssh_options, make sure those options don't include something like user: nil.
You can inspect the value of :ssh_options by running:
$ cap production doctor:variables

Net::SSH::AuthenticationFailed: Authentication failed for user

Local Computer Username: Christopher
Ubuntu Server Username: my_app_name
I have followed the Digital Ocean documentation to set up an Ubuntu 16.04 server with Ruby on Rails and is my first time doing so, though when I get to cap production deploy:initial the console returns Net::SSH::AuthenticationFailed: Authentication failed for user Christopher#12.23.34.45 even though I am able to ssh without a problem into my root and user accounts.
I followed these instructions:
How to connect your droplet with Digital Ocean
https://www.digitalocean.com/community/tutorials/how-to-connect-to-your-droplet-with-ssh
Initial Server Setup with Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04
I generated an ssh public/private key pair on my local computer using:
ssh-keygen -t rsa
I added the public key from my local computer to the servers ~/.ssh/authorized_keys file. I was then able to ssh into my root and user accounts.
I then followed these instructions:
Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
I generated another ssh key, this time on the server and added the public key to my github's deploy keys list. I was then able to successfully clone my repo through ssh.
I run the following commands:
cat ~/.ssh/id_rsa.pub | ssh -p your_port_num deploy#your_server_ip 'cat >> ~/.ssh/authorized_keys'
cap production deploy:initial
And get back:
Net::SSH::AuthenticationFailed: Authentication failed for user Christopher#12.23.34.45
I would really appreciate any help as this is my very first time deploying to an Ubuntu server and I would really like to learn what it is I'm doing wrong. Thank you in advance.
Did you add your key to the Agent?
What do you see when you run:
$ ssh-add -l
If you get 'The agent has no identities.', then add your key with:
$ ssh-add id_rsa_key_name
First of all you need to ssh to your server and run
eval `ssh-agent`
and then
ssh-add ~/.ssh/id_rsa
and now change
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
#
to
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) }
#
I just removed pub from id_rsa.pub.
And then run
cap production deploy:initial
It should work now. Same changes fixed the issues for my app https://www.wiki11.com.
You have :
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
Change it to:
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) }
Keys should have private key location only. Also, enable ssh-agent on local machine using ssh-add. Add ForwardAgent yes in ~/.ssh/config for your Host.
I had some weird problems as long as I did not use bundler. So using capistrano like so then worked again for me:
# good
bundle exec cap production deploy
Instead of just:
# no good
cap production deploy
You need to add the following line to your config/deploy.rb
ssh_options[:forward_agent] = true
Refer this post.

Nothing happens when doing "mina setup"

I'm trying to set up Mina for deploying my Rails app. Unfortunately, when running mina setup or mina deploy, I get to the password prompt, and then nothing happens anymore.
I can manually ssh with the given user and password, so this shouldn't be a problem. But I have no idea, where mina's stuck:
josh#macbuech:~/Documents/Work/MuheimWebdesign/base (features/deployment *)$ mina deploy --verbose
base#josh.ch's password:
-----> Mina: SIGINT received.
Elapsed time: 61.00 seconds
Interestingly, yesterday it was suddenly able to connect (one of a dozen retries worded, I guess):
josh#macbuech:~/Documents/Work/MuheimWebdesign/base (features/deployment *)$ mina deploy --verbose
base#josh.ch's password:
stdin: is not a tty
jailshell: line 3: cd: /var/www/base.josh.ch: No such file or directory
! ERROR: not set up.
The path '/var/www/base.josh.ch' is not accessible on the server.
You may need to run 'mina setup' first.
! Command failed.
Failed with status 15
Then, I couldn't connect to my server anymore (neither by using mina nor plain ssh). I had to call support, and they did something that re-enabled ssh for me. Mina still doesn't work.
In config/deploy.rb, I only added set :user ... and changed :domain, :deploy_to and :repository.
set :domain, 'josh.ch'
set :user, 'base'
set :deploy_to, "/var/www/base.josh.ch"
set :repository, 'git://jmuheim/base'
set :branch, 'master'
Any idea? I'd rather not switch back to Capistrano... Thank you.
This is an old question but this is for any future Googlers that stumble across this. I had the issue described in the question, mina hanging after password entry. Looking around in the issues section of the mina git repo lead me to the fix, albeit a silly one.
In your deploy.rb file put this setting:
set :term_mode, nil
Have you tried run:
mina init
after install gem?
Can you show your deploy.rb?
I didn't have any luck with password authentication. But with public key SSH authentication, it's working fine.
HOW TO: https://www.debian-administration.org/article/530/SSH_with_authentication_key_instead_of_password

Prompt for username/password on login with capistrano

Is there a way in capistrano to have it prompt the user for both the username and the password to the site it's deploying to?
Thanks,
Craig
Have you already uncommented this line from your config/deploy.rb?
# you might need to set this if you aren't seeing password prompts
default_run_options[:pty] = true
Even if it's not straight your question, I use a deploy.yml file in which I have the following variables:
website:
git_user:
passphrase:
server_user:
repository:
In the deploy.rb, I added:
require 'yaml'
CAP = YAML.load_file("./config/deploy.yml")
Then I use it this way:
set :scm_passphrase, CAP["passphrase"]
I didn't put the password of my server cause either I enter them when Capistrano requests it or my computer is in the white list of the server so the deployment is direct.

Resources