Search code examples
githubsshvagrantssh-keys

Github permission denied when cloning in Vagrant


Im using an ubuntu vagrant box for my dev environment.

I've ran the ssh-keygen command and generated a ~/.ssh/id_rsa.pub file and copy and pasted it into my github settings for ssh key.

However whenever I run git clone to a private repository that my account has access to, it gave the error

vagrant@ubuntu2010:/vagrant_data$ git clone git@github.com:aellym0/cs4215_dependent_types.git
Cloning into 'cs4215_dependent_types'...
/vagrant_data/cs4215_dependent_types/.git: Permission denied

I tried to work around this by cloning in my local (not vagrant) into a shared directory with vagrant, but when i am working on vscode connected to vagrant I am unable to write the files in the repo with an EACCESS error.

Here is my vagrant file

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2010"
  config.vm.synced_folder "./data", "/vagrant_data"
end

Here is the vagrant ssh config

Host CS4215
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/haliq/Documents/sch/Y5S2/CS4215/vagrantbox/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL


Solution

  • First, test if your key is working with:

    ssh -Tv git@github.com
    

    If you see a Welcome message ('Hi xxx,...'), you can then check if the error you have means something else. Specifically, a write error because of some Error::EACCES issue, which would have nothing to do with SSH.
    For example, some vendoring issue which should not include .git