git push origin master: permission denied (public key) error

后端 未结 2 2017
暖寄归人
暖寄归人 2021-02-09 11:53

I have set up a git repo on my amazon ec2 ubuntu server instance. I have been trying to push the code onto the server\'s repo from my local machine. The steps that I followed ar

2条回答
  •  一整个雨季
    2021-02-09 12:30

    The complete procedure being:

    1. Add the EC2 public key to your ssh list with the following command

      ssh-add /path/to/myEC2publickey
      
    2. Create a git repository on the EC2 instance with the following commands

      mkdir /path/my_project.git
      cd /path/my_project.git
      git init --bare
      
    3. Connect the local files on your system to your repository with the commands

      cd the_project 
      git init
      git add . 
      git commit -m "Initial git commit message" 
      git remote add origin username@hostname.com:the_project.git 
      git config --global remote.origin.receivepack "git receive-pack" 
      git push origin master
      
    4. Create a public key as the user and add it to the server's authorized keys

      You can do this step by just copying the file id_rsa.pub from the localhost to the servers ~/.ssh/authorized_keys file, as suggested in the previous answer.

    After following these steps if you try the git push, you should not get a "permission denied" error.

提交回复
热议问题