Error connecting via SSH to Bitbucket using Capistrano - ruby-on-rails

I'm a beginner with Rails, Git and Capistrano trying to deploy my first app.
I've setup a VPS with Ubuntu, Nginx and Unicorn installed and now whish to deploy using Capistrano. My app is stored in a Bitbucket repository.
In order to check if I correctly set up Capistrano I ran the following command.
$ cap production git:check and
$ cap production deploy:check
These however, gave me the following error:
INFO [c65cf8c7] Running /usr/bin/env mkdir -p /tmp/testapp/ as developer#[IP]
DEBUG [c65cf8c7] Command: /usr/bin/env mkdir -p /tmp/testapp/
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
developer#[IP]'s password: [password]
INFO [c65cf8c7] Finished in 31.340 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/testapp/git-ssh.sh 0.0%
INFO Uploading /tmp/testapp/git-ssh.sh 100.0%
INFO [2dbfc686] Running /usr/bin/env chmod +x /tmp/testapp/git-ssh.sh as developer#[IP]
DEBUG [2dbfc686] Command: /usr/bin/env chmod +x /tmp/testapp/git-ssh.sh
INFO [2dbfc686] Finished in 0.017 seconds with exit status 0 (successful).
INFO [b0c6add8] Running /usr/bin/env git ls-remote --heads git#bitbucket.org:[USER]/testapp.git as developer#[IP]
DEBUG [b0c6add8] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/testapp/git-ssh.sh" ; /usr/bin/env git ls-remote --heads git#bitbucket.org:[USER]/testapp.git )
DEBUG [b0c6add8] Warning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.
DEBUG [b0c6add8] Error reading response length from authentication socket.
DEBUG [b0c6add8] Permission denied (publickey).
DEBUG [b0c6add8] fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as developer#[IP]: git exit status: 128
git stdout: Nothing written
git stderr: Warning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.
Error reading response length from authentication socket.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: Warning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.
Error reading response length from authentication socket.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Tasks: TOP => git:check
(See full trace by running task with --trace)
It seems like something goes wrong with the SSH-authentication, Standard git commands as push or pull to my git repository work fine.
Grom my local machine $ ssh -T git#bitbucket.com tells me:
Warning: Permanently added the RSA host key for IP address '104.192.143.7' to the list of known hosts.
logged in as [USER].
You can use git or hg to connect to Bitbucket. Shell access is disabled.
From my developer#vps account: ssh -T git#bitbucket.com
Warning: Permanently added the RSA host key for IP address '104.192.143.7' to the list of known hosts.
Permission denied (publickey).
Any idea's?

Capistrano tries to checkout the git repository at the deploy target, i.e. at the VPS. Thus, you need to get the ssh connection to bitbucket working from the VPS machine.
I guess your ssh identities are different at your local host and the VPS and that you have only configured the local-machine ssh key in bitbucket.
Can you compare ~/.ssh/id_rsa.pub on your local machine and while logged as developer at your VPS? If the keys are different, you need to add the public ssh key (the id_rsa.pub file) from the VPS to the bitbucket configuration, so that you can connect to bitbucket from your VPS using ssh.

Related

getting Host key verification failed for git clone https://... url

I am running
git clone https://github.com/ucb-bar/chisel3.git
This gives and error message of
Cloning into 'chisel3'...
Warning: Permanently added the ECDSA host key for IP address '140.82.114.4' to the list of known hosts.
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The command has worked in the past(It is a Part of Jenkins running in docker), and started failing a few min back.
why is my https url getting converted into a git# url?
Run these commands on your terminal and then try to clone the repo
echo "Host *" > ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config

Capistrano DigitalOcean Ubuntu 14.04 fatal: Not a git repository (or any of the parent directories) .git

I have an app that i am working on that i did not set up and i don't have communication with the dev's that did. I have pushed up to it in the past but today for some reason i was not able to. Rails 4 with capistrano. When i looked at the app directory on the server i could find the .gitignore but no .git folder. I did a "git init && git remote add git_ssh_url" but it didn't work. I was thinking about a git clone but i have no clue what that will do to the app. The app is used daily at a company and i'm sure they wouldn't like me screwing it up :) I'm at a loss, Any help is appreciated.
**
Edit
**
So i realized that there is a staging server set up on the same droplet as well and the code to deploy to each is nearly identical. I had no problems updating the staging server
Here is the error code:
refreshing local cache to revision 4ea064e4826a9880c6bac3e0a2689b688e223911 at /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
executing locally: cd /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 4ea064e4826a9880c6bac3e0a2689b688e223911 && git clean -q -d -x -f
fatal: Not a git repository (or any of the parent directories): .git
command finished in 9ms
shell command failed with return code pid 97172 exit 128
So the solution i came across while asking a friend was that somehow the temp cache file that capistrano creates locally here (this path was pulled form the error that i posted above) :
/var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
was throwing the error. At some point there must have been an interrupted deploy that messed up that file. When i ls -la the mpm file above there was a .git file but for whatever reason it wasn't recognized.
The solution was to
rm -rf /var/folders/qb/6fdgzljs1r9ddgkvqk1ky0y40000gn/T/mpm
and rerun the cap production deploy command and it rebuilds the temp cache file and deploys the code.
Hope this helps someone!

Unable to negotiate a key exchange method with Mina deployment

I'm encountering a message like this while deploying with Mina, but not sure why Git is not able to pull the repo.
I've tried switching sshd_config due to Unable to negotiate a key exchange method message, but still can't figure things out. Thanks for helping.
-----> Creating a temporary build path
$ touch "deploy.lock"
$ mkdir -p "$build_path"
$ cd "$build_path"
-----> Cloning the Git repository
$ git clone "git#github.com:repo/project.git" "/home/deploy/project/scm" --bare
Cloning into bare repository '/home/deploy/project/scm'...
Unable to negotiate a key exchange method
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
! ERROR: Deploy failed.
-----> Cleaning up build
$ rm -rf "$build_path"
Unlinking current
$ rm -f "deploy.lock"
OK
! Command failed.
Failed with status 1 (19)
The issue is, that your local SSH client and the remote endpoint at GitHub are unable to agree on a common key exchange method.
This will mostly occur when you poked around with the set of available Key exchange methods or you are using a very old & outdated SSH client which does not support any method which is still regarded as safe.
Interestingly this only occurs on some GitHub Repos: I'm still able to pull from other reports.
To diagnose you can set the following environment variable to see more of the SSH output:
export GIT_SSH_COMMAND="ssh -vv"
To fix it, I added a custom entry in my config_ssh or ~/.ssh/.config allowing more legacy algorithms for that host. Please note this should appear above any Host * section:
# Github needs diffie-hellman-group-exchange-sha1 some of the
# time but not always.
Host github.com
KexAlgorithms curve25519-sha256#libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1

Upload site on Heroku: Host key verification failed

The first time I unloaded a site on Heroku I faced many mistakes. How to correct?
k#k-Aspire-5750G:~/q$ git clone git#github.com:priroda/programmer-site
Cloning into 'programmer-site'...
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
fatal: The remote end hung up unexpectedly
I have 2 files in directory ssh:
k#k-Aspire-5750G:~/.ssh$ ls
id_rsa id_rsa.pub
ssh
Your problem here looks like you're trying to ssh into heroku and clone your repo directly from github?
The problem here is that if you connect to github through ssh (a third party), you will basically have to create an authenticity token (ssh key), so that your third party machine is able to connect to your github repo
--
Fix
Typically, your local machine will be authenticated anyway when you install git, heroku not so. I would therefore recommend you push to Heroku from your local machine, rather than trying to clone through github:
$ git remote add heroku git#heroku.com
$ git add .
$ git commit -a -m "Heroku Deploy"
$ git push heroku master
If you do this first time, you will likely come back with some sort of request for your ssh to be accepted or something - just accept & it should push to Heroku from your local machine
Here is Heroku's take on the matter
Your output looks like a problem with your host verification with Github.com when you're trying to clone and nothing to do with Heroku.
Have a look in your ~/.ssh/known_hosts for a github.com entry and highlight it and remove it. Then try your clone again and it will prompt to verify, say yes and then it should clone successfully.

Rails/Git: can't push my rails code out to the server ('~/git/myapp.git' does not appear to be a git repository)

I'm new to rails and git. I have a rails application under ..../myapp that I would like to deploy using capistrano. I followed the steps described in "Agile Web Development with Rails". To put the application under version control, I did the following:
1) Put my application under version control:
$ cd myapp
$ git init
$ git add .
$ git commit "..."
That all went fine, it created a .git directory under myapp/
2) Created an empty repository on the server:
$ mkdir -p ~/git/myapp.git
$ cd ~/git/myapp.git
$ git --bare init
$ Initialized empty Git repository in /root/git/myapp.git/
3) Created a public key
$ ssh-keygen -t rsa -C "myemail#myemail.com"
$ Your identification has been saved in /root/.ssh/id_rsa.
$ Your public key has been saved in /root/.ssh/id_rsa.pub.
$ The key fingerprint is:
$ d2:16:76:e0:4c:71:de:de:4b:d3:16:94:cc:d7:65:11 myemail#myemail.com
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
4) From my application directory: created the path to the server and push the code
$ git remote add origin ssh://me#host/~/git/myapp.git
$ git push origin master
Now I'm being asked to enter my password, after that:
$ fatal: '~/git/myapp.git' does not appear to be a git repository
$ fatal: The remote end hung up unexpectedly
It might be worth noting that this all happens on the same server, a RHEL 5.7. This is something that confuses me because I basically ssh from my server onto my server. But apparently that's how capistrano does it, even if the application_development and the svn repository are on the same physical machine.
# manojlds:
$ GIT_TRACE=2 git push origin master
$ trace: built-in: git 'push' 'origin' 'master'
trace: run_command: 'ssh' 'me#host' 'git-receive-pack '\''/root/git/myapp.git'\'''
Pretty sure you don't want the tilde ~ in the path. I'd put the actual path in (eg /home/users/)
It is possible that using a relative path and specifying the ssh portion is causing it to break when adding origin.
Try something closer to this:
git remote add origin user#myserver.com:/var/git/myapp.git

Resources