gnutls_handshake() failed: Handshake failed GIT - linux

Everything was working fine but suddenly I am getting the error:
fatal: unable to access
'https://username#bitbucket.org/name/repo_name.git/':
gnutls_handshake() failed: Handshake failed
I am getting this on my computer as well as an EC2 instance. When I tried on another computer then it is working fine there.
I have tried many solutions from Stackoverflow and from other forums. but nothing worked!
On the computer, os is Linux mint 17 and on EC2 instance, Ubuntu 14.04.6 LTS.
What can be the issue and what should I do to fix this issue?

Ran into the same issue on a server with Ubuntu 14.04, and found that on Aug 24, 2020 bitbucket.org changed to no longer allow old ciphers, see https://bitbucket.org/blog/update-to-supported-cipher-suites-in-bitbucket-cloud
This affects https:// connections to bitbucket, but does not affect ssh connections, so the quickest solution for me was to add an ssh key to bitbucket, and then change the remote from https to ssh.
The steps to change the remote I found from here, and they are essentially:
# Find the current remote
git remote -v
origin https://user#bitbucket.org/reponame.git (fetch)
origin https://user#bitbucket.org/reponame.git (push)
# Change the remote to ssh
git remote set-url origin git#bitbucket.org:reponame.git
# Check the remote again to make sure it changed
git remote -v
There is more discussion about the issue on the Atlassian forums at https://community.atlassian.com/t5/Bitbucket-questions/fatal-unable-to-access-https-bitbucket-org-gnutls-handshake/qaq-p/1468075

The quickest solution is to use SSH instead of HTTPS. I tried other ways to fix the issue but it was not working.
The following are steps to replace HTTPS from SSH:
Generate ssh key using ssh-keygen on the server.
Copy the public key from the generated id_rsa.pub file from step 1 and add it at following links depending on the repository host -
Bitbucket - https://bitbucket.org/account/settings/ssh-keys/
Github - https://github.com/settings/ssh/new
Gitlab - https://gitlab.com/profile/keys
Now run the following command to test authentication from the server command line terminal
Bitbucket
ssh -T git#bitbucket.org
Github
ssh -T git#github.com
Gitlab
ssh -T git#gitlab.com
Go to the repo directory and open .git/config file using emac or vi or nano
Replace remote "origin" URL (which starts with https) with the following -
For Bitbucket - git#bitbucket.org:<username>/<repo>.git
For Github - git#github.com:<username>/<repo>.git
For Gitlab - git#gitlab.com:<username>/<repo>.git

sudo bash
mkdir upgrade
cd upgrade
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar xpvfz openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
./Configure
make ; make install
cd ..
wget https://curl.haxx.se/download/curl-7.72.0.tar.gz
tar xpvfz curl-7.72.0.tar.gz
cd curl.7.72.0
./configure --with-ssl=/usr/local/ssl
make ; make install
cd ..
git clone https://github.com/git/git
cd git
vi Makefile, change prefix= line to /usr instead of home
make ; make install

Related

Can't interact with github

My laptop runs arch linux. I wanted to use github to backup my project. In the beginning everything worked fine, I was able to push the first two commits.
Then I wanted to push the third commit but it took forever. From then on every communication (push, pull, clone etc. on multiple repositories) with the remote repository took forever and ended with the error: fatal: could not read from remote repository. There was one exception where i was able to push. Afterwards it was the same again.
The ssh authentication is working. ssh git#github.com delivers the expected response. (ssh -T git#github.com takes forever and is not successful - is this relevant?)
There are a few similar threads but I haven't found a working answer.
What i have already tried:
Checked remote repository (git remote -v): -- is correct
Started ssh-agent and added key (eval `ssh-agent`, ssh-add)
Forcing ssh to use IPv4 (in ~/.ssh/config: AddressFamily inet)
Removed git enviroment variable (unset GIT_SSH)
Tried multiple keys (rsa, ed25519) with/without password
Used the url wiht ssh:// scheme (ssh://git#yourhost:port/path/repo.git)
Updated git
Complete update of the os
Credential helper disabled (git config --global --unset credential.helper)
Checked credentials (git config --global user.name , git config --global user.email)
I even tried to trace the git pull:
GIT_TRACE=2 GIT_TRACE_PACK_ACCESS=2 GIT_TRACE_PACKET=2 GIT_TRACE_PERFORMANCE=2 GIT_TRACE_SETUP=2 git push -u origin main --verbose
With the result:
14:10:30.980851 trace.c:312 setup: git_common_dir: .git
14:10:30.980857 trace.c:313 setup: worktree: /home/alex/Entwicklung/NetCore/ActivityTrackerPC
14:10:30.980863 trace.c:314 setup: cwd: /home/alex/Entwicklung/NetCore/ActivityTrackerPC
14:10:30.980868 trace.c:315 setup: prefix: (null)
14:10:30.980872 git.c:460 trace: built-in: git push -u origin main --verbose
Push nach github.com:2kHammer/ActivityTracker.git
14:10:30.984208 run-command.c:655 trace: run_command: unset GIT_PREFIX; ssh git#github.com 'git-receive-pack '\''2kHammer/ActivityTracker.git'\'''
Then it hangs until the error occures.
For now i copied the project to my raspberry und pushed from there. There it worked without problems.
I am really desperate, git is an essential tool.
Try to re add your ssh key to your ssh agent
ssh-add ~/.ssh/id
where id is the ssh key is the key associated with your github repository

How to run a sudo command, remotely, trough SSH, using an IdentityFile?

I'm trying to trigger an executable file 'post-receive', after pushing some changes to a git repo on a remote machine. Within this file are some commands that require elevated privileges, such as:
sudo -S rm -f $HOME/.build
sudo -S rm -f $HOME/Packages
I've added a remote to my local repo:
git remote add live ssh://dev#ip/home/dev/app/.git
So I can push changes to my remote repo, like this:
git push live master
The 'post-receive' file executes, whenever I push.
However, a password is requested for sudo commands within the 'post-receive' file.
remote: [sudo] password for dev: Sorry, try again.
remote: [sudo] password for dev:
remote: sudo: 1 incorrect password attempt
remote: [sudo] password for dev:
An unexpected event, had I not configured my access trough ssh keys and specified my identity file.
Locally I have setup my SSH keys:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
Then, I've copied the local '~/.ssh/id_rsa.pub' file contents into the remote '~/.ssh/authorized_keys' file.
I've also setup a 'config' file, locally, specifying the location of my identity:
HostName ip
IdentityFile ~/.ssh/id_rsa
At this point, I'm able to ssh into the remote machine, without any passwords, like this:
ssh dev#ip
This was already expected, however, when pushing changes to my remote repo:
git push live master
...it asks me for a password when running the remote 'post-receive' file.
Why am I asked for this password?
What step am I not seeing clearly?
Running:
OS X El Capitan locally
Ubuntu 16.04.1 LTS remotely
Following the Digital Ocean Deployment Tutorial
This has nothing to do with GIT or SSH. Linux distributions by default require any user running a sudo command, even if they have permissions, to enter the password. This can be overridden (see below).
The step to override this :)
Check this answer for example.
You need to add a NOPASSWD directive in your sudoers file for the relevant user. Modified from that answer:
dev ALL = NOPASSWD: ALL
You could replace ALL with a specific command for safety.

How do I pull from a git repo on a remote machine through ssh?

I have several remote machines that need to pull from a repo after I've completed testing and ready to make updates to production (python Flask app and supporting classes). A couple of the machines need to pull from a different branch, as well. I've been SSHing to each machine to run the git pull, but this is getting annoying and time consuming.
I'm trying to run an ssh command that completes a git pull. This is what I've tried:
ssh dev#<remote IP> "cd /home/dev/<repo> && git pull"
And I'm getting a
Permission denied (publickey).
fatal: Could not read from remote repository.
I'm able to run other git commands just fine that don't interact with remote origin. Such as:
ssh dev#<remote IP> "cd /home/dev/<repo> && git remote -v"
When I actually ssh on to the remote machine. I have no problem navigating to the directory and running a git pull.
I also made sure that I added the ssh key to an ssh-agent so that password prompts on the key wouldn't be an issue.
Thought it could potentially be a key permissions issue, so I double checked that the key is readable by the user I'm running the command as.
It's frustrating that I am able to ssh on to the remote machine and run the pull just fine, but cannot run the command with the format above.
Thanks a ton for any help!
Use the -A option.
ssh -A dev#<remote IP> "cd /home/dev/<repo> && git pull"
I ran across the option in a comment here when trying to find the answer to this problem: https://serverfault.com/questions/762983/ssh-and-git-pull-from-remote-server
From https://linux.die.net/man/1/ssh:
If the ForwardAgent variable is set to ''yes'' (or see the description of the -A and -a options above) and the user is using an authentication agent, the connection to the agent is automatically forwarded to the remote side.
From what I understood with your issue, here is my suggestion :
[ Information is somewhat incomplete though ]
GIT reads your id_rsa.pub in root user directory : /home/root/.ssh/id_rsa.pub
That's why your key in /home/your_username/.ssh/id_rsa.pub might not be read by git.
Hence, please check and create the key in /home/root/.ssh/
$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat id_rsa.pub
Hope it helps.

CentOS: Git: "fatal: could not read from the remote repository"

( I have already read through this, and several other posts, thoroughly git: fatal: Could not read from remote repository )
I'm using my own server as a git server. I set it up according to several guides. Everything is fine except any operation that read or writes to the remote git repository.
Problem:
When I try to do anything that interacts with the remote server that I have set up, I get:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
in windows shell. In Cygwin it just hangs.
Quick Background:
I'm using CentOS 7 as the server and Windows 10 as the client.
On the server:
I made a new user 'git'
mkdir /home/git/myproject.git
git init --bare
opened up necessary ports 9418, 22, & 443 using:
"firewall-cmd --permanent --add-port=22/tcp" and
"firewall-cmd --reload"
On the client:
created a folder, created a text file with some text, ran 'git init', 'git add .'
setup rsa keys according to several guides
What Works:
I can ssh into the server fine with windows shell, cygwin and puTTy. The folder /home/git/mproject.git exists. git has been working fine locally using either windows shell or Cygwin.
Attempted solutions:
I've tried:
chmod 600 pyproject.git
chmod 700 pyproject.git
chmod 777 pyproject.git
git remote add origin git#my-site.com:/home/git/myproject.git
git remote add origin git#my-site:/home/git/myproject.git
git remote add origin ssh://git#my-site.com/home/git/myproject.git
git remote add origin ssh://git#my-site.com/repo-<wbr< a="">>/home/git/myproject.git..git
git remote add origin ssh://git#my-site.com/repo-<wbr< a="">>/home/git/myproject.git
git remote add origin git#my-site.com:/home/git/myproject.git
git clone git#my-site.com:/home/git/myproject.git
git remote add origin https://git#my-site.com/home/git/myproject.git
git clone ssh://git#my-site.com/home/git/myproject.git
git clone ssh://git#my-site.com/myproject.git
git clone https://git#my-site.com:myproject.git
git clone ssh://git#my-site.com/home/git/myproject.git
git clone git#my-site.com/home/git/myproject.git
git clone git#my-site.com:/home/git/myproject.git
git clone git#my-site.com/myproject.git
I can log into the server with ssh git#my-site.com just fine. I can also navigate to the /home/git/myproject.git folder. The ports are open. What else could be wrong?
So the problem seems to have been that the client and the server were using versions of git that were very different. The client was using 1.9 I believe, and the server was using 2.6. Not only that, the versions of git differed depending on the whether I was using windows terminal or Cygwin.
Now, after removing old versions and updating git, commands like:
git remote add origin git#mysite.com:/home/git/myproject.git
git push origin master
work correctly.

Gitlab 7.8.4 unable to push with SSH or HTTPS

Our setup:
Gitlab CE
Gitlab 7.8.4
Git-shell: 2.5.4
Gitlab API: v3
Ruby: 2.1.5p273
Rails: 4.1.1
This is test is on a private repository owned by the same user that is trying to push to it (user is admin). Environment check is clean with no errors. Same error whether we try HTTPS or SSH. SSH worked before the upgrade.
Error:
git push -u origin master
/usr/local/lib/ruby/2.1.0/json/common.rb:155:in `parse': 757: unexpected token at 'false' (JSON::ParserError)
from /usr/local/lib/ruby/2.1.0/json/common.rb:155:in `parse'
from /home/git/gitlab-shell/lib/gitlab_access_status.rb:13:in `create_from_json'
from /home/git/gitlab-shell/lib/gitlab_net.rb:34:in `check_access'
from /home/git/gitlab-shell/lib/gitlab_shell.rb:25:in `exec'
from /home/git/gitlab-shell/bin/gitlab-shell:16:in `<main>'
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Similar issue:
https://gitlab.com/gitlab-org/gitlab-ce/issues/838
It would appear that we have proper access via HTTPS and SSH, but something on the server, perhaps with git-shell is not right.
What we've done so far:
sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production
Made sure 'AllowUsers git' was in sshd_config
ssh-keygen -A
ssh-keygen: generating new host keys: ED25519
Tried different version of git-shell back to 2.2.0.
# ssh git#gitlab.domain.com
PTY allocation request failed on channel 0
Welcome to GitLab, Anonymous!
Connection to gitlab.domain.com closed.
As Geoff pointed out, my issue was a badly configured gitlab-shell/config.yml. Once the type for gitlab_url was corrected, we were able to push and pull without any issues with HTTPS and SSH.

Resources