No access to remote repository - node.js

I am deploying my node.js app.
I am using git hooks and creating a remote repository.
In the image below you can see that i have added the remote 'adiproduction' to which i will push from my local repo.
Below i am pasting the image of content in post-receive file of hooks.
Following is the error when i try to push my code on 'adiproduction' remote.
ubuntu#35.154.65.179: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Edit:
I tried running the ssh -Tv ubuntu#35.154.65.179 command. And i got the following output.

try to run the code with "sudo"
sudo helps you to run the command with root privilege
and secondly, if you dont want use sudo so please set the ssh key on your git account, this link will helps you to set the ssh key-
'https://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/'
and lastly if above solution not helps then please delete the current repository and try to clone again useing following command with ssh clone link-
git clone -b
thank you

Related

Clone private git repo to remote host using sudo

I would like to run the following command:
ssh -A josh#remote_ip sudo git clone git#github.com:private/private-repo.git /home/ec2-user/private-repo
but I get an error:
Cloning into '/home/ec2-user/private-repo'...
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 works when I want to clone into a directory I own (~/private-repo) without sudo. The command doesn't work if I include sudo into a directory I already own.
Since I need to use sudo to write into the other user's directory, how can I get this command to work? Logging in as ec2-user is not a possible solution.
Thank you to #chepner for pointing me in the direction of the issue: my ssh key does not get passed to ~root/.ssh when I use sudo.
To fix this, I used visudo to add this line to my /etc/sudoers file:
Defaults env_keep += "SSH_AUTH_SOCK"
Source

Need help cloning a GitHub repository because of public key issues

I am trying to clone a private GitHub repository in a server that I am trying to get up and running on a virtual machine.
No matter what I do, I keep getting the following error:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have tried a bunch of things. For starters, I made sure that I made my rsa keys correctly by following GitHub's tutorial. I am also sure that my public rsa key found at ~/.ssh/id_rsa.pub was correctly copied over to my GitHub account's ssh keys.
My config file at ~/.ssh/config looks like the following:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
I have tried cloning a public repository and a private repository, and both don't work.
When I go to clone the repository I am executing the following command:
sudo git clone git#github.mit.edu:<GitHub Name>/<Repo Name>.git
If I execute the command without sudo, I get the following error:
fatal: could not create work tree dir '<Repo Name>'.: Permission denied
I am inside of a Python virtual environment when I do all of this. Does that make any difference?
I have been reading Stack Overflow posts related to this matter, but none of them are helping me address my issue.
Any help would be greatly appreciated! Thank you!
You are using sudo so Git is using ssh keys of user root.
To make this work you'd have to call git without sudo.
So when I don't use sudo I get the error fatal: could not create work
tree dir 'cardlearning'.: Permission denied
Make sure current user has write permission in directory you are executing the clone.
You can't clone into existing directory so as a workaround you can:
$ sudo mkdir tmp
$ sudo chown $USER: tmp
$ git clone git#github.mit.edu:<GitHub Name>/<Repo Name>.git tmp/cardlearning
$ mv tmp/cardlearning ./cardlearning
$ rmdir tmp
Check that your user has permissions to write to the directory you are in.
or execute
git clone git#github.mit.edu:<GitHub Name>/<Repo Name>.git ~/myRepo
to place it in the myRepo subdirectory of your home directory.
Do not use sudo to edit your ssh config when using a ~ referenced path, as you may end up editing the root user's ssh preferences and not your users. Likewise do not clone repositories using sudo as it will attempt to connect using the root user's ssh key.

Unable to connect to Linux git Repo from Windows machine

So recently I've been trying to set up a Git server to manage personal projects and work. I created a bare Git repo on a spare laptop running Ubuntu and I installed Git Bash on my Windows machine. Right now I'm having some issues in actually being able to clone my Ubuntu git server to my Windows computer.
I used git remote add origin myserver#myserver-Dell-System:/home/myserver/CentralRepo.git but
whenever I try to clone to my Windows machine, Git bash spits out this error:
ssh: Could not resolve hostname myserver#myserver-Dell-System: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and repository exists.
I double checked my add to make sure the address of my Git server was correct and I assume Git bash for Windows comes with OpenSSH.
Does anyone know why this is happenning and how I can get my Windows machine to sucessfully clone from a server to itself? Thanks!
A valid ssh url would be
auser#myserver-Dell-System
You can check if you can resolve and connect to that server with
ssh -T auser#myserver-Dell-System
That supposes that you have generated a public/private ssh key pair, and added your public key to ~auser/.ssh/authorized_keys file first.
See "Adding SSH Keys to authorized_keys"

Unable to git clone

I want to clone repository by using following command.
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
I have got following error with this command.
dev#ubuntu:/a/WebRtc/Tools$
dev#ubuntu:/a/WebRtc/Tools$git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Cloning into 'depot_tools'...
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
dev#ubuntu:/a/WebRtc/Tools$
I have tried this in following ways:
Update git version.
Try with Ubuntu 15.10 and 14.04.4.
Try same command in windows machine, it working.
Such an error message during a clone (not a push or pull) indicates that git is not able to properly create the local repo.
See for instance "Cannot git clone to VMWare shared folder", where the impossibility to create hard-link was problematic.
Check:
if your user has the right to create file/symlink/hardlink, or
if there is some kind apparmor policy which would prevent/limit the creation of files in your setup, or
if /a/WebRTC is a mounted folder with restricted rights

make git clone with sudo

when I make git clone with ssh from a user prompt it works properly.
git clone ssh://URL.com/soft.git soft_git
the ssh key id_rsa and id_rsa.pub are under /home/user/.ssh
my purpose is the execute git with sudo but I got the following error
Cloning into '/home/user/git/soft'...
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I create a folder /root/.ssh and I copy the ssh keys into it but I got the same error
how to execute git with sudo properly.
When you run git using sudo, git will run as root. Because git is running as root, ssh is running as root. Because ssh is running as root, it is trying to log on to the remote server as root. The remote server is not okay with this (as it should be!)
You will need to do two things:
Put the username in your URL: ssh://myusername#URL.com/soft.git.
Make your SSH key available to the root user, because it will look under /root/.ssh instead of /home/user/.ssh. (You could also probably point SSH at the correct key, but I don't know how to do this, and SSH is picky about permissions.)
On my computer (Ubunutu 18.04), adding SSH_AUTH_SOCK=$SSH_AUTH_SOCK after sudo and before git fixed the problem:
sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone git#github.com:my-github-account/my-repo.git
Normally, sudo's SSH_AUTH_SOCK environment variable won't be set properly. Executing the git clone with SSH_AUTH_SOCK=$SSH_AUTH_SOCK sets sudo's SSH_AUTH_SOCK environment variable to whatever it is for you.
This way, you don't need to add an extra .ssh dir for sudo with copies of your keys, which is what I think one of the other answers suggests.
The solution is more fully explained in this rather old github gist:
https://gist.github.com/scottjacobsen/4281310
P.S. I'm adding a new answer several years later; I googled a solution to this problem, and this SO Q/A is one of the first things that comes up.
Normally the default remote ssh user is the same as your user name. If you're using sudo this will be root which probably isnt' going to work. You need to supply the remote username.
sudo git clone ssh://username#URL.com/soft.git soft_git
You can generally resolve git ssh issues easier by trying to login to the remote with plain ssh. You'll get better diagnostics and can see what's going wrong.
sudo ssh ssh://URL.com/

Resources