Capistrano login Net::SSH failure - ruby

Suddenly, Capistrano began to return a SSH issue:
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: staging.myserver.com
(Net::SSH::AuthenticationFailed: root) connection failed for:
staging.myserver.com (Net::SSH::AuthenticationFailed: root)
My deploy.rb contains:
require 'capistrano/ext/multistage'
ssh_options[:forward_agent] = true
ssh_options[:keys] = ["myserver_rsa"]
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :scm, "git"
set :application, "myapp"
set :repository, "git#bitbucket.org:project/myapp.git"
set :use_sudo, false
set :deploy_via, :remote_cache
and at my config/deploy/staging.rb
server 'staging.myserver.com', :app, :web, :db, primary: true
set :branch, 'staging'
set :rails_env, "staging"
set :deploy_to, "/var/rails/#{application}"
set :user, "root"
set :password, "my_triple_check_password_login"
set :domain, "staging.myserver.com"
Tests made by me before posting here:
Try to login via ssh (ssh -v staging.myserver.com)
=> Logged successfully without prompt my password. (using myserver_rsa key)
Agent Forward
=> Enabled in server and in local
Try to login via ssh without keys:
=> prompted for password. Copy and paste it from staging.rb and logged perfectly.
Change server root password. => Try to login with new password via ssh root#... worked nice. but via capistrano, fails.
Run in IRB a Net SSH script to login.
=> Logged in and return a hostname result from bash.
This issue starts yesterday suddenly. I really don't have more ideas :/
First of all, nothing was change at server either Cap deploy configs.
Thanks!

I found!
In my /etc/ssh_config root section I had:
Host *
SendEnv LANG LC_*
XAuthLocation /opt/X11/bin/xauth
ForwardAgent yes
PasswordAuthentication yes
I was need to create a section to my staging environment:
Host staging.myserver.com
IdentityFile /Users/hlegius/.ssh/myserver_rsa
ForwardAgent yes
RSAAuthentication no
PasswordAuthentication no
and edit my config/deploy.rb to add: default_run_options[:pty] = true
Aaaaaaaaand it's works!

This error is due to the authentication failure. Capistrano can't connect to the deploying server with given username and password. I already done the deployment for a server and I am now deploying to a New server. Then I got this error.
It prompted me to give the password for new server. I entered the new server password. But its showing this error.
I changed the domain here
set :domain, "my-new-ip-or-domain" => my new server domain
But forgot to change the username here in my deploy.rb
set :user, "my-new-username"
After giving the correct username and password it works perfectly!

Related

How to make a SSH connection using pageant on terraform for provisioning files?

How to make a SSH connection via pageant on terraform? I'm trying to provision files with file provisioner running on SSH connection. According to docs, on windows, only supported ssh agent is Pageant, but it does not explain how to configure it.
https://www.terraform.io/docs/provisioners/connection.html
Even after adding directory of PuTTY to the PATH env var (which is included in GitExtension), terraform does not seem to detect that, and keep failing to make SSH connection.
Connecting via plink.exe works, so my SSH key is correctly added to the Pageant.
plink core#<ip-address-of-host>
File provisioner works when I pass the content of private_key directly like this, but that's not what I want.
connection {
type = "ssh"
host = aws_instance.instance.public_ip
user = "core"
agent = false
private_key = file(var.private_key_path)
}
You have to set the agent parameter to true:
agent - Set to false to disable using ssh-agent to authenticate. On Windows the only supported SSH authentication agent is Pageant.
agent = true

PostgresSQL SETPGPASSWORD not setting password

I am trying to push to Heroku and I got the password prompt with the wrong user like many people, so I went and did
SET PGUSER=[pg_username]
SET PGPASSWORD=[pg_password]
I am putting in the command:
heroku pg:push mylocaldb DATABASE_URL --app my-app
It changed the username but the password didn't work and I get the error message:
connection to database "mylocaldb" failed: FATAL: password authentication failed for user "Janet"
How do I change/find the password?
my pg_hba file looks like this :
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all [redacted] trust
# IPv6 local connections:
host all all [redacted] md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all [redacted] trust
host replication all [redacted] trust

SSH localhost authentication failed mac

Testing ssh functionality on my Mac and wondering why SSH into localhost just with the command:
$ ssh localhost
Prompts me for a password, and responds with
Password:
localhost: Authentication failed.
on the first attempt (after entering correct local password), and consistently follows up with more prompts if I enter the wrong password or nothing:
$ ssh localhost
Password:
Password:
Password:
squid#localhost's password:
Received disconnect from ::1 port 22:2: Too many authentication failures
Authentication failed.
The behavior is different if I enter the right password, so I know my password is correct. But why would authentication still fail? Please help!
UPDATE : Figured it out. It's a setting with local file sharing. Not sure why but out of the box configurations don't allow for an ssh into localhost. To fix: Open System Preferences -> Sharing -> Check Remote Login (make sure your user is included)

capistrano3 permission denied (using proxy)

I'm trying to migrate my capistrano v2 script to the new v3.4 version.
All went well with development stage: I have one EC2 instance, and the deploy completed without errors.
I'm having some troubles with my production script, because I've got a proxy (EC2 instance) before my production servers (EC2 instances too); in my capistrano v2 script all was working, now I'm using cap-ec2 + capistrano v3.4 to deploy my application only to tagged servers, but when I try it I get "Permission Denied", my production servers refuse my key.
Maybe I've set something wrong with proxy parameters in my script, can you please help me?
Thanks a lot!!
Here you can find proxy parameters:
CAPISTRANO V2 (working)
set :gateway, "deploy#xxx.xxx.xxx.xxx"
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
ssh_options[:port] = "22"
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa_deploy_myapp")]
CAPISTRANO V3 (not working)
require 'net/ssh/proxy/command'
set :ssh_options, {
user: "deploy",
keys: %w("~/.ssh/id_rsa_deploy_myapp"),
auth_methods: %w(publickey),
forward_agent: true,
port: 22,
proxy: Net::SSH::Proxy::Command.new('ssh xxx.xxx.xxx.xxx -W %h:%p')
}

Permission denied after deploy app with capistrano

I have a deploy.rblike this
set :application, "api"
set :repository, "git#github.com/org/api.git"
default_run_options[:pty] = true
set :scm_passphrase, "passwd"
set :scm, :git
set :user, "deploy"
set :use_sudo, false
set :deploy_to, "/var/www"
set :deploy_via, :remote_cache
role :web, "192.168.0.95" # Your HTTP server, Apache/etc
role :app, "192.168.0.95" # This may be the same as your `Web` server
role :db, "192.168.0.95", :primary => true # This is where Rails migrations will run
role :db, "192.168.0.95"
as you can see, I'm doing a deploy to our intranet...
After this, I executed bundle exec foreman start on our server and when I access the app, i see this:
Permission denied - /var/www/releases/20120719190900/tmp/cache
I tried to chmod and chown our www folder, but nothing changed...
What am I missing here?
Thanks
Can you try set :use_sudo, true instead of false?
I've just created the folder cache inside tmp folder and it worked! Strange thing...

Resources